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?
<snip>From what I know, in the future versions of PHP short tags are going
to be
disabled by default.
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
Philip Olson wrote:
<snip>From what I know, in the future versions of PHP short tags are going
to be
disabled by default.Common misunderstanding but the short_open_tag directive will never be
disabled by default.
Unless you have used --disable-short-tags during configure.. :)
--Jani
Philip Olson wrote:
<snip>From what I know, in the future versions of PHP short tags are going
to be
disabled by default.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.
Philip Olson wrote:
<snip>From what I know, in the future versions of PHP short tags are going
to be
disabled by default.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.
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:
The following RFC mentions this decoupling, yet was declined:
And lastly, the general topic of short tags came up recently while
several people discussed PHP 6:
In summary: It's a topic people don't want to talk about. :)
Regards,
Philip
"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
Philip Olson wrote:
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:The following RFC mentions this decoupling, yet was declined:
And lastly, the general topic of short tags came up recently while
several people discussed PHP 6: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.
Roman I wrote:
Philip Olson wrote:
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:The following RFC mentions this decoupling, yet was declined:
And lastly, the general topic of short tags came up recently while
several people discussed PHP 6:In summary: It's a topic people don't want to talk about. :)
Regards,
PhilipThanks 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 < 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
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
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 < 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
Hannes Magnusson wrote:
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 < 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]
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
Hannes Magnusson wrote:
On Fri, Jun 5, 2009 at 07:47, Rasmus Lerdorfrasmus@lerdorf.com
wrote: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 < 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]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
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:
- short_open_tag setting removed in 6, <? is no longer PHP code tag
under any circumstances. - <?= is always recognized by PHP as analogue to <?php echo
- 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
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:
- short_open_tag setting removed in 6, <? is no longer PHP code tag
under any circumstances.- <?= is always recognized by PHP as analogue to <?php echo
- 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) aboveAnd 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 :)
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.
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
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