Bug #76851 [NEW]: Nonsense error message when "['" used next to variable in string

From: Date: Fri, 07 Sep 2018 17:42:19 +0000
Subject: Bug #76851 [NEW]: Nonsense error message when "['" used next to variable in string
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216921@lists.php.net to get a copy of this message
From: teo8976 at gmail dot com Operating system: PHP version: 7.3.0beta3 Package: *General Issues Bug Type: Bug Bug description:Nonsense error message when "['" used next to variable in string Description: ------------ See below Test script: --------------- <?php $a='ipsum'; $ss = "lorem $a['foo'] dolor"; Expected result: ---------------- I think this shouldn't throw a syntax error at all, and should result in the value "lorem ipsum['foo'] dolor" being assingned to the variable $ss. However, if I'm wrong and the use of "$a['foo']" is actually illegal (because of the apostrofe following the opening square bracket next to a variable name), then a SENSIBLE and understandable error message should be thrown. Actual result: -------------- Throws this syntax error which makes no sense: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) "unexpected ''" obviously makes no sense. You are stating that the parser unexpectedly found an empty string. While I understand that, internally, this could be the case (the syntax is wrong and hence something that should have been filled with something is instead empty), the error message is not workable, because there's no way I can tell what the unexpectedly empty string is. '' literally matches everything, so if you tell me "unexpected ''", the offending piece of code could be ANYWHERE (within the given line). Not to mention you are implying that '' is a T_ENCAPSED_AND_WHITESPACE. The parser is erroring out at least one level too deep. Instead of complaining of an unexpected "nothing", it should complain of the unexpected sequence of things that causes that nothing to be nothing. To me it looks like the unexpected thing here is the "'" right after the "[", so the error should say so. That is, if that is actually illegal in the first place, which as I said, I'm not even sure of. -- Edit bug report at https://bugs.php.net/bug.php?id=76851&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76851&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76851&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76851&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76851&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76851&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76851&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76851&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76851&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76851&r=support Expected behavior: https://bugs.php.net/fix.php?id=76851&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76851&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76851&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76851&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76851&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76851&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76851&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76851&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76851&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76851&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76851&r=mysqlcfg

« previous php.bugs (#216921) next »