Edit report at http://bugs.php.net/bug.php?id=53298&edit=1

 ID:                 53298
 Comment by:         bastard dot internets at gmail dot com
 Reported by:        jost dot boekemeier at googlemail dot com
 Summary:            // $msg_text = '?>...';
 Status:             Bogus
 Type:               Bug
 Package:            *General Issues
 Operating System:   any
 PHP Version:        5.2.14
 Block user comment: N
 Private report:     N

 New Comment:

@jost dot boekemeier:  I'll preface this comment with "I'm just a
regular PHP user, not a PHP org member".



Changing the // behavior would break the usage in in-line php, shown on
the 2nd example on the doc page.  Something like the following would no
longer work...



<p>This is a paragraph about <?php echo $subject; // important comment
here ?>.</p>



Looks ugly here, but with any IDE, the color-coding makes it all pretty
intelligible.  The doc page is pretty clear about this comment usage. 
The workaround to comment out any entire block containing any "?>"
symbol would be to use the /* */ symbols instead.  Of course this goes
against convenience and habit, and as other users have noted, this
breaks lines with */ appearing anywhere (ie. regex strings, nested
comments, etc).  But fixing -those- problems would break things
elsewhere, like in this example of sourcecode documentation...



function do_something(/* integer */ $some_int, /* string */ $some_str)
{/* do something */}



This report seems more like a feature request.  I'd vote for something
like skipping the in-comment PHP mode escape if the // symbol doesn't
appear on a same line as any opening PHP tag.  Though I'm sure devs can
think of a better solution.


Previous Comments:
------------------------------------------------------------------------
[2010-11-14 14:38:58] jost dot boekemeier at googlemail dot com

fel...@php.net, thank you very much for taking the time to comment my
request, even though you haven't understood it.



1. commenting out a valid variable definition should not cause the PHP
parser to *suddenly* parse the definition! 



2. this is completely unexpected, even after reading the documentation







Please either fix this bug. Change the PHP parser to handle 

   $var = "val<?ue";

and

// $var = "val<?ue";



equally: The parser should either stop at the <? or not. For example if
you force the programmer to always write "val<"."?ue", the problem
vanishes.



The current behaviour means that you can expose the contents of an
existing PHP file (including database passwords) by commenting out a
simple variable definition. -- Line-comments can be problematic, but it
shouldn't have such a drastic effect that the script returns
unevaluated. 





Or please clearly document this bug, so that programmers do not use
//-style comments to comment-out variable definitions.

------------------------------------------------------------------------
[2010-11-12 21:43:23] fel...@php.net

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



------------------------------------------------------------------------
[2010-11-12 20:39:36] bastard dot internets at gmail dot com

"?>" is meant to break out of PHP when encountered in a single-line
comment (see
http://www.php.net/manual/en/language.basic-syntax.comments.php).

------------------------------------------------------------------------
[2010-11-12 12:19:20] jost dot boekemeier at googlemail dot com

corrected mail address

------------------------------------------------------------------------
[2010-11-12 12:08:24] jost dot boekemeier at googlemail dot com

Description:
------------
PHP Parser doesn't handle comments as such



<?php

echo 1+2;

// $msg_text =
'?>RCP_11/11/10_12:31:52_070%_E009.56.35,7_N53.32.39,6_003KM/H_278DEG_0M_2_4_0_1,6_00_0';

echo 1+2;



should print 33, and not print the script unevaluated.

Test script:
---------------
<?php

echo 1+2;

// $msg_text =
'?>RCP_11/11/10_12:31:52_070%_E009.56.35,7_N53.32.39,6_003KM/H_278DEG_0M_2_4_0_1,6_00_0';

echo 1+2;



Expected result:
----------------
33

Actual result:
--------------
3RCP_11/11/10_12:31:52_070%_E009.56.35,7_N53.32.39,6_003KM/H_278DEG_0M_2_4_0_1,6_00_0';

echo 1+2;




------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=53298&edit=1

Reply via email to