|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70983 commenting a printf line causes script to fail with "Unexpected end of file"
Submitted: 2015-11-27 06:35 UTC Modified: 2017-01-09 05:48 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at rossw dot net Assigned:
Status: Wont fix Package: Reproducible crash
PHP Version: 5.6.16 OS: FreeBSD 10.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
9 + 9 = ?
Subscribe to this entry?

 [2015-11-27 06:35 UTC] php at rossw dot net
A quoted string containing ?> is treated correctly inside an active code block, but causes errors due to being handled differently if the line is commented out.

I can see how it could be argued that ?> should not appear, but there are times you might actually WANT to print it. Simply commenting out the line should not materially alter the way the (otherwise perfectly healthy) script runs.

Test script:

	printf("This is a test\n");
	if(1 > 0) 
//		printf("?> Debug code\n");
		printf("Got here\n");

Expected result:
php is seeing the "?> Debug code" as quoted text, and handles it correctly while the line is not commented. As soon as the line is commented, php is seeing the quoted ?> as the end of the code and errors.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-12-02 12:09 UTC] codekestrel at googlemail dot com
That behaviour is explicitly defined here:

<ST_IN_SCRIPTING>"#"|"//" {
        while (YYCURSOR < YYLIMIT) {
                switch (*YYCURSOR++) {
                        case '\r':
                                if (*YYCURSOR == '\n') {
                                /* fall through */
                        case '\n':
                        case '?':
                                if (*YYCURSOR == '>') {
                                /* fall through */


        yyleng = YYCURSOR - SCNG(yy_text);


Removing the "case '?':" clause would break the following inline code:

<?php echo "Hello, World!"; // my comment ?> Remainder

Which should print: Hello, World! Remainder

Everything on the same line after the comment including after the closing tag are commented out.
 [2016-07-26 16:05 UTC] dave at mudsite dot com
I understand this request.  PHP ought to know if this is a single-line execute, and handle accordingly.

  <?php echo "hello"; // comment ?> output
  <?= echo "hello"; // comment ?> output
should each run with output:
  hello output

That said, the request here:
  if (foo) {
    // ?>

Should not throw a syntax error.  I have no idea what the consensus on this kind of issue is, however, (i've done) and it would be simple enough to track what line <?php, or <?, or <?= start on, and what line we see // ?>, and if they aren't the same, then ignore the ?> inside the comment.

if (*YYCURSOR == '>' && (CG(zend_opentag_lineno) == CG(zend_lineno))) {
 [2017-01-09 05:48 UTC]
-Status: Open +Status: Wont fix
 [2017-01-09 05:48 UTC]
Since this is against a security fix only branch, and since a patch against a supported branch would need to be different, please can you open a PR on github against a supported branch.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 10:01:33 2024 UTC