Bug #70983 [Com]: commenting a printf line causes script to fail with "Unexpected end of file"

From: Date: Wed, 02 Dec 2015 12:09:43 +0000
Subject: Bug #70983 [Com]: commenting a printf line causes script to fail with "Unexpected end of file"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-197556@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70983&edit=1

 ID:                 70983
 Comment by:         codekestrel at googlemail dot com
 Reported by:        php at rossw dot net
 Summary:            commenting a printf line causes script to fail with
                     "Unexpected end of file"
 Status:             Open
 Type:               Bug
 Package:            Reproducible crash
 Operating System:   FreeBSD 10.2
 PHP Version:        5.6.16
 Block user comment: N
 Private report:     N

 New Comment:

That behaviour is explicitly defined here:

<ST_IN_SCRIPTING>"#"|"//" {
        while (YYCURSOR < YYLIMIT) {
                switch (*YYCURSOR++) {
                        case '\r':
                                if (*YYCURSOR == '\n') {
                                        YYCURSOR++;
                                }
                                /* fall through */
                        case '\n':
                                CG(zend_lineno)++;
                                break;
                        case '?':
                                if (*YYCURSOR == '>') {
                                        YYCURSOR--;
                                        break;
                                }
                                /* fall through */
                        default:
                                continue;
                }

                break;
        }

        yyleng = YYCURSOR - SCNG(yy_text);

        RETURN_TOKEN(T_COMMENT);
}

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.


Previous Comments:
------------------------------------------------------------------------
[2015-11-27 06:35:20] php at rossw dot net

Description:
------------
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:
---------------
<?php

	printf("This is a test\n");
	if(1 > 0) 
	{
//		printf("?> Debug code\n");
		printf("Got here\n");
	}
	printf("Finished\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.



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



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


Thread (4 messages)

« previous php.bugs (#197556) next »