|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-08-08 06:32 UTC] nikic@php.net
[2015-08-08 06:32 UTC] nikic@php.net
-Assigned To:
+Assigned To: nikic
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 06:00:02 2025 UTC |
Description: ------------ I've noticed some AST nodes (arrays, ++, yield, etc.) may have the wrong line numbers. Here's an example PHP code: 1: <?php 2: yield 3: 4: // gap 5: 6: function() { yield; }; PHP 7.0.0beta3 will report: Fatal error: The "yield" expression can only be used inside a function in wrong-line-number.php on line 6 That message is wrong. The yield on line 6 is correct. The fatal error is actually on line 2. We can see the AST has the wrong line number. Here's the output from php-ast. AST_STMT_LIST @ 1 0: AST_YIELD @ 6 0: AST_CLOSURE @ 6-6 flags: 0 name: {closure} 0: AST_PARAM_LIST @ 6 1: null 2: AST_STMT_LIST @ 6 0: AST_YIELD @ 6 0: null 1: null 3: null 1: null The first AST_YIELD has the line number 6. After quick inspection, I see the parser often delay the construction of AST node and capture the line number after parsing 1~2 tokens, which may be a line or more below the actual beginning of the AST node. The consequences are incorrect line numbers from runtime errors. Test script: --------------- <?php yield // gap function() { yield; }; Expected result: ---------------- Fatal error: The "yield" expression can only be used inside a function in wrong-line-number.php on line 2 Actual result: -------------- Fatal error: The "yield" expression can only be used inside a function in wrong-line-number.php on line 6