#49202 [Opn]: php array documentation missing information on invalid key return value

From: Date: Sat, 22 Aug 2009 09:22:53 +0000
Subject: #49202 [Opn]: php array documentation missing information on invalid key return value
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-2645@lists.php.net to get a copy of this message
ID: 49202 Updated by: torben@php.net Reported By: receive at cprogramming dot ca Status: Open Bug Type: Documentation problem Operating System: Web server PHP Version: Irrelevant New Comment: The resultant value is the same as for checking any undefined variable--it's null. That's the only value it can logically have; any other type would indicate a known value, which would be nonsense since you cannot know the type of something which does not exist. Previous Comments: ------------------------------------------------------------------------ [2009-08-10 07:37:57] niel dot archer at blueyonder dot co dot uk Any default value would depend on context, as it does for all variables. See http://docs.php.net/manual/en/language.types.type-juggling.php If, as it appears, you want to know if the key exists. It would be better to test for that with the appropriate function ;-). Replace line 3 with: 3) if (!isset($a["testing_invalid_index"])){ ------------------------------------------------------------------------ [2009-08-09 19:16:12] receive at cprogramming dot ca Description: ------------ http://uk2.php.net/manual/de/language.types.array.php There's no explanation in the online documentation of what value is returned when you access an array with a key/index that doesn't exist. For example, on line 3, I cannot use the documentation to tell me what $a["testing_invalid_index"] will return to me. Does it return 0 or "" or null or false, or does it give an error? 1) $a[] = array(); 2) $a["sdfads"] = "booger"; 3) if ($a["testing_invalid_index"] == false){ 4) echo "Something"; 5) } Reproduce code: --------------- --- From manual page: language.types.array --- Expected result: ---------------- Documentation should indicate how an expression containing an array with an invalid key/index is evaluated. Actual result: -------------- Documentation is missing information on how an expression containing an array with an invalid key/index is evaluated. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49202&edit=1

« previous php.doc.bugs (#2645) next »