Bug #78693 [Nab]: @ operator evaluates @$foo['undefined'] to $foo[0] on strings

From: Date: Fri, 18 Oct 2019 20:42:19 +0000
Subject: Bug #78693 [Nab]: @ operator evaluates @$foo['undefined'] to $foo[0] on strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223277@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78693&edit=1 ID: 78693 User updated by: david at vielhuber dot de Reported by: david at vielhuber dot de Summary: @ operator evaluates @$foo['undefined'] to $foo[0] on strings Status: Not a bug Type: Bug Package: *General Issues Operating System: Ubuntu 18 PHP Version: 7.3.10 Block user comment: N Private report: N New Comment: That was quick, thank you very much for the explanation. Any chance this coercion gets changed? Previous Comments: ------------------------------------------------------------------------ [2019-10-18 20:22:43] 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 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. ------------------------------------------------------------------------ [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

« previous php.bugs (#223277) next »