# Is there a technical reason <?= considered a "short tag"?

- Thread: https://externals.io/message/44029
- Original archive: https://news-web.php.net/php.internals/44029
- Started by Roman I on 2009-05-19T00:33:00+00:00
- Messages: 16
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #44029 — Roman I — 2009-05-19T00:33:00+00:00

URL: https://externals.io/message/44029#44029

From what I know, in the future versions of PHP short tags are going to be
disabled by default. Considering the conflicts with XML syntax, that's
understandable. However, is there a technical reason to consider <?=  a
short tag? From what I know, it doesn't conflict with XML notation, and it
is really handy when writing templates. Moreover, keeping it independent
from short tags settin is likely to decrease the number of scipts that will
need to be rewritten, since some of them use the echo shortut without ever
using vanilla <? (again, templates).

I see this code in zend_language_scanner.l:

<INITIAL>"<%="|"<?=" {
 if ((yytext[1]=='%' && CG(asp_tags)) || (yytext[1]=='?' && CG(short_tags)))
{
  zendlval->value.str.val = yytext; /* no copying - intentional */
  zendlval->value.str.len = yyleng;
  zendlval->type = IS_STRING;
  BEGIN(ST_IN_SCRIPTING);
  return T_OPEN_TAG_WITH_ECHO;
 } else {
  zendlval->value.str.val = (char *) estrndup(yytext, yyleng);
  zendlval->value.str.len = yyleng;
  zendlval->type = IS_STRING;
  return T_INLINE_HTML;
 }
}

Would it be possible to split this rule in two?

<INITIAL>"<%=" {
 if ((yytext[1]=='%' && CG(asp_tags))) {
  zendlval->value.str.val = yytext; /* no copying - intentional */
  zendlval->value.str.len = yyleng;
  zendlval->type = IS_STRING;
  BEGIN(ST_IN_SCRIPTING);
  return T_OPEN_TAG_WITH_ECHO;
 } else {
  zendlval->value.str.val = (char *) estrndup(yytext, yyleng);
  zendlval->value.str.len = yyleng;
  zendlval->type = IS_STRING;
  return T_INLINE_HTML;
 }
}

<INITIAL>"<?=" {
    zendlval->value.str.val = yytext; /* no copying - intentional */
    zendlval->value.str.len = yyleng;
    zendlval->type = IS_STRING;
    BEGIN(ST_IN_SCRIPTING);
    return T_OPEN_TAG_WITH_ECHO;
}

If so, are are there any obvious negative consequences of doing so?

---

## #44031 — Philip Olson — 2009-05-19T07:00:53+00:00

URL: https://externals.io/message/44029#44031 · In reply to: #44029

> From what I know, in the future versions of PHP short tags are going  
> to be
> disabled by default.
<snip>

Common misunderstanding but the short_open_tag directive will never be  
disabled by default. There are distributed php.ini-* files that  
disable them, but those don't contain default values.

Regards,
Philip

---

## #44032 — Jani Taskinen — 2009-05-19T09:50:35+00:00

URL: https://externals.io/message/44029#44032 · In reply to: #44031

Philip Olson wrote:
> 
> 
> 
> > […]
> <snip>
> 
> Common misunderstanding but the short_open_tag directive will never be 
> disabled by default. 

Unless you have used --disable-short-tags during configure.. :)

--Jani

---

## #44101 — Roman I — 2009-05-30T19:49:34+00:00

URL: https://externals.io/message/44029#44101 · In reply to: #44031

Philip Olson wrote:
>
> 
>
> > […]
> <snip>
>
> Common misunderstanding but the short_open_tag directive will never be
> disabled by default. There are distributed php.ini-* files that
> disable them, but those don't contain default values.

This neither answers nor invalidates the original question, though.

---

## #44139 — Philip Olson — 2009-06-03T21:13:34+00:00

URL: https://externals.io/message/44029#44139 · In reply to: #44101

> Philip Olson wrote:
> > […]
>
> This neither answers nor invalidates the original question, though.

Unfortunately I do not remember everything about this but do know that:

   - Decoupling <?= from short_open_tag was discussed, and did not  
happen
   - Allowing it to be enabled at runtime was discussed, and did not  
happen
   - The issues with <?= and <? are similar... an invalid PI

I've not read every thread or discussion on this (there are many) but  
CVS speaks for itself. Here's one thought comparing the two viewpoints:

   - http://marc.info/?l=php-internals&m=120614525214419&w=2

The following RFC mentions this decoupling, yet was declined:

   - http://wiki.php.net/rfc/shortags

And lastly, the general topic of short tags came up recently while  
several people discussed PHP 6:

   - http://wiki.php.net/summits/pdmnotesmay09

In summary: It's a topic people don't want to talk about. :)

Regards,
Philip

---

## #44142 — Michael — 2009-06-03T21:37:57+00:00

URL: https://externals.io/message/44029#44142 · In reply to: #44139

"In summary: It's a topic people don't want to talk about. :)"

The <?= issue is really quite significant however, it seems quite a 
common topic of confusion at freenode's ##php. Lots of ZF examples and 
other mainstream code uses <?= and it seems a very good idea to use 
it... however it's very difficult to guarantee it will be available to 
all users (something important in the open source world).

It's a growing issue that needs to be addressed.

Michael

---

## #44169 — Roman I — 2009-06-05T03:45:10+00:00

URL: https://externals.io/message/44029#44169 · In reply to: #44139

Philip Olson wrote:
> 
>
> > […]
>
> Unfortunately I do not remember everything about this but do know that:
>
>    - Decoupling <?= from short_open_tag was discussed, and did not
> happen
>    - Allowing it to be enabled at runtime was discussed, and did not
> happen
>    - The issues with <?= and <? are similar... an invalid PI
>
> I've not read every thread or discussion on this (there are many) but
> CVS speaks for itself. Here's one thought comparing the two viewpoints:
>
>    - http://marc.info/?l=php-internals&m=120614525214419&w=2
>
> The following RFC mentions this decoupling, yet was declined:
>
>    - http://wiki.php.net/rfc/shortags
>
> And lastly, the general topic of short tags came up recently while
> several people discussed PHP 6:
>
>    - http://wiki.php.net/summits/pdmnotesmay09
>
> In summary: It's a topic people don't want to talk about. :)
>
> Regards,
> Philip

Thanks for the references. I've seen the RFC, but I haven't seen that thread
you've linked to. It does contain almost all things I could say here.
However, I haven't found very strong argument against decoupling in that
thread either. :)

Even without short tags, PHP will not be a well-formed XML processing
instruction in many cases. For example,
<?php $x = '<?>'; ?>
or, more commonly:
<root test="<?php echo $value; ?>" />

Plain <? has an additional problem of affecting the ability to include XML
files from PHP source code. However, it seems to me that using the syntax
above will have exactly the same consequences for XML well-formedness as
using <?=. Since the syntax above is allowed with short_open_tags off,
disallowing  <?= with that setting off looks like an overkill. That's my
reasoning behind starting this thread, anyway.

Admittedly, I haven't said anything new here, but I've rephrased an old
argument in a nicer way. :)Maybe it will do some good.

---

## #44171 — Rasmus Lerdorf — 2009-06-05T05:47:22+00:00

URL: https://externals.io/message/44029#44171 · In reply to: #44169

Roman I wrote:
> Philip Olson wrote:
> > […]
> 
> Thanks for the references. I've seen the RFC, but I haven't seen that thread
> you've linked to. It does contain almost all things I could say here.
> However, I haven't found very strong argument against decoupling in that
> thread either. :)
> 
> Even without short tags, PHP will not be a well-formed XML processing
> instruction in many cases. For example,
> <?php $x = '<?>'; ?>
> or, more commonly:
> <root test="<?php echo $value; ?>" />
> 
> Plain <? has an additional problem of affecting the ability to include XML
> files from PHP source code. However, it seems to me that using the syntax
> above will have exactly the same consequences for XML well-formedness as
> using <?=. Since the syntax above is allowed with short_open_tags off,
> disallowing  <?= with that setting off looks like an overkill. That's my
> reasoning behind starting this thread, anyway.
> 
> Admittedly, I haven't said anything new here, but I've rephrased an old
> argument in a nicer way. :)Maybe it will do some good.

Right, I think that is actually the conclusion we came to at one point.
 I don't remember the discussion that caused the RFC to be declined.  I
would be in favour of reversing that decision wherever it came from.

Nobody is going to pass a PHP script through an XML parser, and PHP
itself will never be well-formed, so that is a lost cause.  We'd have to
start tossing CDATA blocks and write code like:

  if( 2 &lt; 3 ) echo "2 is less than 3";

And that just isn't going to happen.  The only valid argument against
short_tags itself is that it clashes with named PI tags and <?= does not
have that same problem.

-Rasmus

---

## #44172 — Stanislav Malyshev — 2009-06-05T06:58:23+00:00

URL: https://externals.io/message/44029#44172 · In reply to: #44171

Hi!

> Right, I think that is actually the conclusion we came to at one point.
>  I don't remember the discussion that caused the RFC to be declined.  I
> would be in favour of reversing that decision wherever it came from.

Amen to that!

> And that just isn't going to happen.  The only valid argument against
> short_tags itself is that it clashes with named PI tags and <?= does not
> have that same problem.

So, could we have <?= reclassified as "normal tag" and have short_tags 
killed for 6? Please? :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #44174 — Hannes Magnusson — 2009-06-05T07:43:11+00:00

URL: https://externals.io/message/44029#44174 · In reply to: #44171

> Nobody is going to pass a PHP script through an XML parser, and PHP
> itself will never be well-formed, so that is a lost cause.  We'd have to
> start tossing CDATA blocks and write code like:
>
>  if( 2 &lt; 3 ) echo "2 is less than 3";

No you don't. & and < are perfectly legal in PIs


> And that just isn't going to happen.  The only valid argument against
> short_tags itself is that it clashes with named PI tags and <?= does not
> have that same problem.

<?= is not a valid target name either, so it has the same problem.

4]   	NameStartChar	   ::=   	":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6]
| [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] |
[#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF]
| [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

-Hannes

---

## #44175 — Rasmus Lerdorf — 2009-06-05T07:53:08+00:00

URL: https://externals.io/message/44029#44175 · In reply to: #44174

Hannes Magnusson wrote:
> 
> > […]
> 
> No you don't. & and < are perfectly legal in PIs
> 
> 
> > […]
> 
> <?= is not a valid target name either, so it has the same problem.
> 
> 4]   	NameStartChar	   ::=   	":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6]
> | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] |
> [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF]
> | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]

The point still stands.  If you are trying to parse PHP with an XML
parser, you are doing it wrong.  I have absolutely no problems annoying
the one or two pedantic people who care about this for the benefit of
thousands who don't.

-Rasmus

---

## #44179 — Stan Vassilev — 2009-06-05T13:12:49+00:00

URL: https://externals.io/message/44029#44179 · In reply to: #44174

Hi,

> Plain <? has an additional problem of affecting the ability to include XML
> files from PHP source code.

readfile('file.xml');

> From what I know, in the future versions of PHP short tags are going to be
> disabled by default. Considering the conflicts with XML syntax, that's
> understandable.

// no conflict
<?='<?xml version="1.0"?>'?>

// conflict with full PHP tags
<?php echo '?>' ?>

// conflict with full PHP tags
<?php $a = $b; /* ?> */ ?>

I think these four examples should render any argument containing "XML" and 
"PHP" in the same sentence invalid.

My suggestion is, follow your own notes: "Leave short tags alone - never 
talk about it again" (http://wiki.php.net/summits/pdmnotesmay09).

Regards,
Stan Vassilev

---

## #44186 — Philip Olson — 2009-06-05T18:45:56+00:00

URL: https://externals.io/message/44029#44186 · In reply to: #44175

> Hannes Magnusson wrote:
> > […]
>
> The point still stands.  If you are trying to parse PHP with an XML
> parser, you are doing it wrong.  I have absolutely no problems  
> annoying
> the one or two pedantic people who care about this for the benefit of
> thousands who don't.

The RFC was marked declined due to repeated discussions and lack of  
change, but declined without much fanfare or official yay or nay  
discussion aside from a mention in a recent related thread, IRC, and  
CVS.

So it feels like decoupling <?= from short_open_tag is on the table.  
Rasmus or Stas, could you please propose exactly how this might  
happen? Like when, and if the fate of short_open_tag would be affected  
(which is never deprecate nor disable by default).

And while few want to talk about short tags (again), it's worth noting  
that a discussion specific to decoupling really hasn't taken place  
except for silence and a few "yeah, that might be alright... sometime"

Regards,
Philip

---

## #44187 — Stanislav Malyshev — 2009-06-05T19:17:37+00:00

URL: https://externals.io/message/44029#44187 · In reply to: #44186

Hi!

> So it feels like decoupling <?= from short_open_tag is on the table. 
> Rasmus or Stas, could you please propose exactly how this might happen? 

My proposal would be very simple:
1. short_open_tag setting removed in 6, <? is no longer PHP code tag 
under any circumstances.
2. <?= is always recognized by PHP as analogue to <?php echo
3. To prepare folks for this, 5.4 may have this:
3a. short_open_tag is off by default, but <? is recognized when it's on
3b. <?= is always recognized, as in (2) above

> And while few want to talk about short tags (again), it's worth noting 
> that a discussion specific to decoupling really hasn't taken place 
> except for silence and a few "yeah, that might be alright... sometime"

I was kind of under impression I talked about it so much at the time 
that everybody's sick of it, but maybe I'm wrong :)
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com

---

## #44188 — Brian Moon — 2009-06-05T19:29:24+00:00

URL: https://externals.io/message/44029#44188 · In reply to: #44187

> Hi!
>
> > […]
>
> My proposal would be very simple:
> 1. short_open_tag setting removed in 6, <? is no longer PHP code tag
> under any circumstances.
> 2. <?= is always recognized by PHP as analogue to <?php echo
> 3. To prepare folks for this, 5.4 may have this:
> 3a. short_open_tag is off by default, but <? is recognized when it's on
> 3b. <?= is always recognized, as in (2) above
>
> > […]
>
> I was kind of under impression I talked about it so much at the time
> that everybody's sick of it, but maybe I'm wrong :)

No, #1 in your list is why people got sick of it.  You want to bind the 
decoupling of <?= as a short tag to the removal of short tags.  They are 
two different issues.

The only change I care to see is that <?= is always valid.  That would 
let me clean up templates in so many places.  As it is, I can't use that 
in any distributed project because "short tags" may be disabled.  Leave 
short tags forever for all I care.  Probably more work to remove them 
than it is to leave them in.

-- 

Brian.
--------
http://brian.moonspot.net/

---

## #44191 — Stanislav Malyshev — 2009-06-05T21:05:38+00:00

URL: https://externals.io/message/44029#44191 · In reply to: #44188

Hi!

> No, #1 in your list is why people got sick of it.  You want to bind the 
> decoupling of <?= as a short tag to the removal of short tags.  They are 
> two different issues.

I do not insist on 1. I'd be ok with not touching short tags but just 
moving <?= to non-short. I just think once <?= is non-short, nobody 
needs short tags anymore, but I could be wrong. We may do it in 2 steps. 
We might even have <?= made non-short in 5.3 maybe :)

> The only change I care to see is that <?= is always valid.  That would 

Same here.
-- 
Stanislav Malyshev, Zend Software Architect
stas@zend.com   http://www.zend.com/
(408)253-8829   MSN: stas@zend.com
