php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16066 <?PHP tag warning!
Submitted: 2002-03-14 09:29 UTC Modified: 2012-12-27 04:51 UTC
From: dave at netready dot biz Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.1.1 OS: Linux (Debian)
Private report: No CVE-ID: None
 [2002-03-14 09:29 UTC] dave at netready dot biz
There is an error with the parsing of the PHP start tag "<?PHP"...

Turn on all error reporting...

error_reporting( E_ALL );

This works ok

<?PHP /*Hello*/?>

However without the space it outputs a warning:
"Warning: Use of undefined constant PHP - assumed 'PHP'"

<?PHP/*Hello*/?>

But this (correctly) doesn't output anything...
<?/*Hello*/?>

If you put code after the comment it is worse.
<?PHP/*Hello*/
print "Hello";
?>

This actually dies with a "parser error", but again this 
works if you use the shorter tag.

<?/*Hello*/
print "Hello";
?>

Outputs "Hello" as expected.

The fact that it works when you use "<?" instead of "<?PHP" is what leads me to believe this is a bug and not just a feature of the language.  Surely they should both behave the same?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-03-14 21:04 UTC] yohgaki@php.net
<?php, <?, <% is token that must be separated by spaces. (You need space after them) Therefore, this is not a bug .
 [2002-03-15 05:27 UTC] dave at netready dot biz
You say you must have a space after <?PHP, <? and <%.
Then the bug is with the error reporting because:

<?/*Hello*/
print "Hello";
?>

does not report an error, either way something is wrong here, because the behaviour is not consistant for all three of those tokens.

I have looked at "Chapter 5. Basic syntax" section of the manual, this explains the use of the <?PHP, <? and <%... it does not say anything about requiring a space.  Could this BUG be anything to do with the fact that you can do "<?=" and "<%=" but not "<?PHP=" ... which seems a little strange seeing as <?PHP is supposed to be the "propper" token.
 [2002-03-15 06:59 UTC] yohgaki@php.net
PHP will not raise error since it's not PHP script.
There is no way to raise error, if it's not a PHP script.
 [2002-03-15 07:46 UTC] dave at netready dot biz
Funny... If (as you claim) this:

<?/*Hello*/
print "Hello";
?>

is not a PHP script, howcome PHP actually prints out "Hello" in this situation? (with no warnings or errors) Is PHP in the habit of running code that is "not PHP script" ?

So far both of your reasons for marking this bug as "bogus" have contradicted this example, which was in my original bug report and is something you could easily reproduce yourself.  This gives me the impression that either you've not bothered reading my comments, you haven't understood what I'm saying or you think its not important enough to be worth fixing so you're making up lame excuses.

Please read this bug report properly and think about it before marking it as "bogus" again.  If you don't understand it or can't be bothered with it please refer it to someone who does/can, rather than just closing it.

Whatever response you do give, PLEASE make sure it doesn't contradict something I've already explained, that is very frustrating.
 [2002-03-15 21:06 UTC] yohgaki@php.net
Apperently, short tag does not need spaces after open tag :)
However, there is nothing wrong and there is nothing we should fix here.

i.e. Changing "<?php" open tag without following spaces is not good idea at all.

I'm sure you agree following code is ugly.
<?phpprint_r($GLOBALS)?> 
while
<?print_r($GLOBALS)?>
is not.


 [2002-03-18 04:07 UTC] dave at netready dot biz
I totally agree that you 

<?phpprint_r($GLOBALS)?> 

is horrible.

The reason I found this problem was that I was commenting out a section of HTML using PHP tags.  I just stuck in
<?PHP/* and */?> but it confused me when it didn't work.

If this space is a requirement it really should be mentioned somewhere in the documentation.  I'm going to stick a comment on the "Basic Syntax" section of the manual, where it talks about these tags.  

I do still think they should all be consistant though. ;o)
 [2002-03-18 06:26 UTC] goba@php.net
<?php is XML compliant, and in XML you need to
put a spacw there. While <? is a shortcut, and
as usual, people would like to use it in the
short way, with no space after it, like
<?=SID?>

Goba
 [2002-03-18 07:05 UTC] dave at netready dot biz
How about a decent warning/error when you miss the space then?... At the moment you either get (with all warnings on) "Warning: Use of undefined constant PHP - assumed 'PHP' or it's dies with a "parser error" at line whatever, depending what you have put after the <?PHP token.

As a programmer I am quite curious to know how the start token has been implemented, it is obviously a lot more complicated than it looks...I thought it would be (sudo-code :)

if token="<?" or token="<%" or token="<?PHP" then
    start_php
else
    don't.
end if

(...hmmm actually that's VB, not sudo code! - my deepest apologies) but judging from the behaviour it would seem that it looks for "<?" or "<%" and then if there is a "PHP " it simply ignores it? whereas "PHP" (without the space) doesn't match so it thinks its a constant.

Or is this all to do with delimiting characters?  obviously with something like <?PHPprint"Hello";?> the scanner would not find a delimiter so I assume you'd end up with a token "PHPprint" ? which the parser doesn't understand.

I digress... an error message is all I ask.
 [2012-12-27 04:43 UTC] MTee7 at LightHouse57 dot com
This little item bit me in the ass lately.

I was in the habit of using just <? in my scripts.

Then my server upgraded to 5.3, but they didn't have the 'short tag' flag set...supposedly a security risk?

At any rate now my scripts all died.

SO I did a global replace of <? with <?php to solve the problem.

BUT, there were many places in the code where <? had no spaces after it. So now there were parts of code that also had no spaces, and it didn't like that at all.

I agree that <?echo 'Hey beautiful' looks better than <?phpecho 'Hey Beautiful'........but code is not supposed to 'look good'......it's supposed to be CONSISTENT.

So imo if <? starts php code...in that it parses the next character after the ?....well then it should ALSO parse the first character after ?php 

There......another few blows to the apparently dead horse.....

And puleeeeeze....no comments about the age of this post....Google brought it to my attention.......and Google apparently thinks it has value....and just because a post is old doesn't mean it has lost it's value to others......so THERE.......z
 [2012-12-27 04:51 UTC] rasmus@php.net
Sorry, as per the XML spec, a PI tag, which is what PHP uses, is <?
PHP<whitespace>
It simply isn't valid starting tag without the whitespace. Something else could 
easily come along that uses <?p or perhaps <?ph or even <?phpe as the processing 
instruction name. Nothing can start processing these tags until a valid one is 
found.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 14:01:31 2024 UTC