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

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

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

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

<% is from ASP... and that's, uh, yeah, I'll refrain from my comment.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

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

Post 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.
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

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

Post 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 <%.
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Maugrim_The_Reaper wrote: <table width=100%>.
That is invalid xhtml, the attribute's value should be quoted
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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.
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

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

Post 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. :)
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

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

Post 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 ?>
Gambler
Forum Contributor
Posts: 246
Joined: Thu Dec 08, 2005 7:10 pm

Post by Gambler »

Is it Cacth 22 thread or something?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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"
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post 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 =".
Post Reply