php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49202 php array documentation missing information on invalid key return value
Submitted: 2009-08-09 19:16 UTC Modified: 2009-08-26 06:34 UTC
From: receive at cprogramming dot ca Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Web server
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: receive at cprogramming dot ca
New email:
PHP Version: OS:

 

 [2009-08-09 19:16 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-10 07:37 UTC] 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-22 09:22 UTC] torben@php.net
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.
 [2009-08-26 06:34 UTC] svn@php.net
Automatic comment from SVN on behalf of torben
Revision: http://svn.php.net/viewvc/?view=revision&revision=287729
Log: Clarified what will happen when attempting to access an undefined array index.
Addresses Bug #49202.
 [2009-08-26 06:34 UTC] torben@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 04:00:01 2026 UTC