Bug #76294 [Nab]: Variable expansion taking place into string when using undefined constant.

From: Date: Wed, 02 May 2018 11:07:40 +0000
Subject: Bug #76294 [Nab]: Variable expansion taking place into string when using undefined constant.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215007@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76294&edit=1 ID: 76294 Updated by: requinix@php.net Reported by: dpastor at comvive dot es Summary: Variable expansion taking place into string when using undefined constant. Status: Not a bug Type: Bug Package: *General Issues Operating System: Ubuntu Linux 64 PHP Version: 7.2Git-2018-05-02 (Git) Block user comment: N Private report: N New Comment: "$countries[mexico]" is fine. "{$countries[mexico]}" is not. https://3v4l.org/mfjOY Previous Comments: ------------------------------------------------------------------------ [2018-05-02 11:03:33] spam2 at rhsoft dot net this code is simply wrong $greet="Hi $friends, welcome to $countries[mexico]"; this one does what you think the above does $greet="Hi $friends, welcome to {$countries[mexico]}"; ------------------------------------------------------------------------ [2018-05-02 10:59:47] requinix@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 Quotes aren't necessary for the simple interpolation syntax because that's just how it's always been. Complex syntax requires quotes like you want. http://php.net/manual/en/language.types.array.php http://php.net/manual/en/language.types.string.php ------------------------------------------------------------------------ [2018-05-02 10:54:13] dpastor at comvive dot es Description: ------------ Code using array string indexes without quotes is interpreted in newer versions of PHP as undefined constants. However, the same behaviour is not observed when variable expansion takes place. See the example code. Test script: --------------- <?php $friends="friends"; $countries['mexico']="land of the good people"; //echo $countries[mexico] will result in a warning. //This, however, results in the correct expansion. $greet="Hi $friends, welcome to $countries[mexico]"; echo $greet; Expected result: ---------------- Unless I am mistaken, I expect the parser to be consistent and tell me that $countries[mexico] is trying to reference an undefined constant when using it inside variable expansion (as it does outside of it). ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76294&edit=1

« previous php.bugs (#215007) next »