Bug #76294 [Nab]: Variable expansion taking place into string when using undefined constant.
| From: | requinix@php.net | Date: | Wed, 02 May 2018 11:35:27 +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-215010@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:
30 minutes ago you said
> this code is simply wrong
> $greet="Hi $friends, welcome to $countries[mexico]";
That is incorrect: the code is fine.
Then you said
> this one does what you think the above does
> $greet="Hi $friends, welcome to {$countries[mexico]}";
I thought you were trying to say that code would work (incorrect), but now I think I misunderstood
and you were trying to say that it will give the warning that @dpastor was expecting to see
(correct).
And yes, your example output does demonstrate the "complex syntax requires quotes like you
want" I said earlier.
And yes, the bug report is about there not being a warning for the simple syntax. What I said
earlier addresses that.
Previous Comments:
------------------------------------------------------------------------
[2018-05-02 11:28:52] spam2 at rhsoft dot net
and that's what this bugreport is about: "Warning: Use of undefined constant mexico -
assumed 'mexico'" missing
php > echo "welcome to $countries[mexico] test";
welcome to MEXICO test
------------------------------------------------------------------------
[2018-05-02 11:24:28] spam2 at rhsoft dot net
nonsense - i have thousands lines of code in the style of " {$arr['whatever']} "
and as you can see below it's correct
php > $countries = ['mexico'=>'MEXICO'];
php > echo "welcome to {$countries['mexico']} test";
welcome to MEXICO test
php > echo "welcome to {$countries[mexico]} test";
Warning: Use of undefined constant mexico - assumed 'mexico' (this will throw an Error in
a future version of PHP) in php shell code on line 1
welcome to MEXICO test
php >
------------------------------------------------------------------------
[2018-05-02 11:07:39] requinix@php.net
"$countries[mexico]" is fine. "{$countries[mexico]}" is not.
https://3v4l.org/mfjOY
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=76294
--
Edit this bug report at https://bugs.php.net/bug.php?id=76294&edit=1