Page 1 of 2

Does anyone knows why PHP uses '<?php' instead of '<%'

Posted: Mon Feb 06, 2006 4:37 pm
by Gambler
IIRC, short version (<?) is "bad", because it conflicts with XML. However, <?php is quite a long tag for templates, and there is no <?php=. Just curious.

Posted: Mon Feb 06, 2006 4:44 pm
by feyd
<% is from ASP... and that's, uh, yeah, I'll refrain from my comment.

Re: Does anyone knows why PHP uses '<?php' instead of '&l

Posted: Mon Feb 06, 2006 4:46 pm
by hawleyjr
Gambler wrote:(<?) is "bad", because it conflicts with XML.
Where did you hear that? PHP is parsed on the server XML is text.

Posted: Mon Feb 06, 2006 4:52 pm
by Gambler
Where did you hear that? PHP is parsed on the server XML is text.
PHP mailing lists. XML uses <? for processing instructions. So PHP sees <?, tries to parse the code after it, and gives you parsing error.
<% is from ASP... and that's, uh, yeah, I'll refrain from my comment.
Support for <% tags is already available for PHP, and you can turn it on with your ini file. That's why I mentioned it.

Re: Does anyone knows why PHP uses '<?php' instead of '&l

Posted: Mon Feb 06, 2006 5:32 pm
by Christopher
Gambler wrote:IIRC, short version (<?) is "bad", because it conflicts with XML.
Actually <?language is the standard, so it should be properly <?xml and <?php. It is Microsoft (as usual) that is not following the standards with <%.

Posted: Mon Feb 06, 2006 6:02 pm
by Maugrim_The_Reaper
Wow, things are so bad they break their own standards...;) Short and ASP style tags are a nuisance, <?php it should always be. Can also be noted that malformed html/php using %> can also cause issues - think <table width=100%>.

Standards exist for a very good reason - so extra typing or not its generally a good idea to follow them.

Posted: Mon Feb 06, 2006 6:08 pm
by josh
Maugrim_The_Reaper wrote: <table width=100%>.
That is invalid xhtml, the attribute's value should be quoted

Posted: Mon Feb 06, 2006 6:23 pm
by d3ad1ysp0rk
jshpro2 wrote:
Maugrim_The_Reaper wrote: <table width=100%>.
That is invalid xhtml, the attribute's value should be quoted
Point being? When working in a design/development company, it's not always under your list of duties to be converting the code to acceptable xhtml.

ASP tags were like that before xhtml was widely accepted and used.

Re: Does anyone knows why PHP uses '<?php' instead of '&l

Posted: Mon Feb 06, 2006 8:06 pm
by Roja
Gambler wrote:IIRC, short version (<?) is "bad", because it conflicts with XML. However, <?php is quite a long tag for templates, and there is no <?php=. Just curious.
Because php isn't a template.

Don't worry, there are plenty of people that will want to argue otherwise, so I'll just walk right past that line, and stand firm that it answers your question: That is *why* PHP uses <?php and not a short-tag. Because being a template isn't at all a focus, concern, or even desired role for PHP. Its a full-fledged server-side language, and the proper delim for that should be <?php.

The only time it will conflict is if you open a php file in an (x)html editor. Guess what? Its not html. Its a programming language, that can produce html. :)

Posted: Mon Feb 06, 2006 8:11 pm
by Gambler
Standards exist for a very good reason
Actually <?language is the standard
Since PHP is pre-processor, XML standards do not apply here. Stuff like <option value="<?php echo $z; ?>"> is not valid XML anyway, and <?php is not a real processing instruction. The only worry is that PHP parser will get confused.

Posted: Tue Feb 07, 2006 3:13 am
by Maugrim_The_Reaper
jshpro2 wrote:
Maugrim_The_Reaper wrote: <table width=100%>.
That is invalid xhtml, the attribute's value should be quoted
Yes, it is invalid. Since when did that stop it being used though? ;) I spent time last year working on a legacy application written back in 2000. It was riddled with examples like this - took ages to fix everything to xhtml transitional. Not everyone has jumped on the XHTML bandwagon just yet. Quirks mode forgives much...

Re: Does anyone knows why PHP uses '<?php' instead of '&l

Posted: Tue Feb 07, 2006 5:31 am
by Chris Corbyn
Gambler wrote:and there is no <?php=.
How do you mean? You can use short echo tags but I wouldn't advise it...

Code: Select all

<?= $foo ?>

Posted: Tue Feb 07, 2006 12:01 pm
by Gambler
Is it Cacth 22 thread or something?

Posted: Tue Feb 07, 2006 12:12 pm
by josh
Because some servers migh have them disabled, there's also talk about them being disabled in PHP6 but I personally don't buy it. My code is scattered with them, if it can save me time while coding why the hello not? If I need to upgrade I just do a file find and replace for <?= and replace it with <?php echo

edit: hmm did you edit your thread, I was replying to your "why"

Posted: Tue Feb 07, 2006 1:32 pm
by Roja
jshpro2 wrote:Because some servers migh have them disabled, there's also talk about them being disabled in PHP6 but I personally don't buy it.
http://www.php.net/~derick/meeting-notes.html#id66

1. Kill "<%" but keep "<?".
2. Jani will prepare a patch that disallows mixing different open/close tags.
3. Will not add "<?php =".