Bug #78693 [Opn->Nab]: @ operator evaluates @$foo['undefined'] to $foo[0] on strings
Edit report at https://bugs.php.net/bug.php?id=78693&edit=1
ID: 78693
Updated by: requinix@php.net
Reported by: david at vielhuber dot de
Summary: @ operator evaluates @$foo['undefined'] to $foo[0]
on strings
-Status: Open
+Status: Not a bug
Type: Bug
-Package: Unknown/Other Function
+Package: *General Issues
Operating System: Ubuntu 18
PHP Version: 7.3.10
Block user comment: N
Private report: N
New Comment:
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
The @ operator is not changing the behavior. All it does here is hide notices and warnings from you.
If you were able to see those then you might understand that using [] on an integer is not the same
as using it on a string.
$foo = 1337;
$foo['undefined'];
> Notice: Trying to access array offset on value of type int
$foo = '1337';
$foo['undefined'];
> Warning: Illegal string offset 'undefined'
Since string offsets are supposed to be integers, PHP coerces 'undefined' to 0.
Previous Comments:
------------------------------------------------------------------------
[2019-10-18 20:14:50] david at vielhuber dot de
Description:
------------
$foo = 1337;
@$foo['undefined'] // evaluates to null
$foo = '1337';
@$foo['undefined'] // evaluates to '1'
Desired behaviour: @$foo['undefined'] should also evaluate to null.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78693&edit=1
Thread (4 messages)