#42461 [Opn->Bgs]: //?> causing parse errors
ID: 42461
Updated by: jani@php.net
Reported By: theblazingangel at aol dot com
-Status: Open
+Status: Bogus
-Bug Type: *Compile Issues
+Bug Type: Scripting Engine problem
Operating System: Win XP
PHP Version: 5.2.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2007-08-28 15:01:10] theblazingangel at aol dot com
Description:
------------
//?> (with anything or nothing in-between // and ?>) can cause parse
errors.
i noticed this while constructing regex patterns, when i used // to
comment out lines containing >?, it gave me this error:
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION
in <file> on line 466
it can be extremely confusing when you suddenly get this error after
commenting out a line like:
//preg_match_all("/(?:^|[ ]+)(?!\-)\+?(?:(?>\"|\')(?=((?:[
]\\1|$\\1)+))\\1|([^ ]+))(?:|(?=[ ])|$)/s", $search, $matches);
i get that in a situation like the following, ?> should be taken as the
end of the php code: <?php echo $data //print data ?>
however, in the situation i was in, (where commenting out the line
resulted in the ?> being taken as the php terminator, and therefore
causing an error because the if/loop/function/class/etc hadn't
finished), shouldn't the php parser, before reporting the error, attempt
to continue as if the ?> was part of the comment?
the solution is to use /**/ rather than //, but it seems counter
intuitive to me that it fails in the frst place in such a situation...
Reproduce code:
---------------
<?php
if(1==1)
{
//?>
}
?>
Expected result:
----------------
for example code:
a blank page
for the code i discovered it in:
it should have continued with no error
Actual result:
--------------
with the example:
Parse error: syntax error, unexpected $end in <file> on line 8
with the code in the description, in the file i used it in (a wordpress
plugin):
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION
in <file> on line <x>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42461&edit=1
Thread (3 messages)