|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-02-24 20:09 UTC] robertbasic dot com at gmail dot com
[2012-05-11 07:09 UTC] a1283465 at jnxjn dot com
[2013-11-18 18:45 UTC] chris dot baker dot gr at gmail dot com
[2015-06-08 20:17 UTC] cmb@php.net
-Status: Open
+Status: Duplicate
-Assigned To:
+Assigned To: cmb
[2015-06-08 20:17 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 06:00:01 2025 UTC |
Description: ------------ If you try to access an undefined index on an array, you will get an error. But if you try the same on bool(false) PHP will silently accept it and ignores the error. Please note that this is especially dangerous on database results, where you get false instead of an array when there is no result. If you try the same on a valid array with an invalid index you will get a E_NOTICE. So trying to use the array operator on a non-array should at least raise an E_STRICT error, indicating that there is a problem, instead of silently continuing to use the wrong result for further calculations. Test script: --------------- $array1 = false; $array2 = array('a'=>3); echo 5+3*$array1['a']; // output: 5 var_dump($array1['b']); // output: NULL var_dump($array2['b']); // output: <b>Notice</b>: Undefined index: b