Edit report at https://bugs.php.net/bug.php?id=45290&edit=1

 ID:                 45290
 Updated by:         ni...@php.net
 Reported by:        cole dot snodgrass at gmail dot com
 Summary:            always throw an E_NOTICE when accessing an undefined
                     index
-Status:             Open
+Status:             Closed
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   linux
 PHP Version:        5.2.6
-Assigned To:        
+Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

$string['foo'] will raise a notice as of PHP 5.4, so I'd say this is fixed, so 
I'm closing here.


Previous Comments:
------------------------------------------------------------------------
[2011-01-27 15:06:40] bugs dot php dot net at moesen dot nu

See also:
* Bug #48560 - E_STRICT does not report error if booleans or ints are used as 
arrays
* Request #37676 - using Array access operator [] on boolean variable does not 
show Notice

Dupe it to the latter?

------------------------------------------------------------------------
[2008-06-17 16:13:01] col...@php.net

FWIW: $string['foo'] is equivalent to $string[0] and in your case it won't 
trigger any notice indeed because the offset 0 is defined.

------------------------------------------------------------------------
[2008-06-17 04:24:15] cole dot snodgrass at gmail dot com

Description:
------------
It seems strange that when the strictest level or error reporting is enabled an 
E_NOTICE is thrown when attempting to access a non-existent key of an array, 
but nothing is thrown when attempting to access a non-existent key of a bool, 
or a string, or it appears any other variable type.  An E_NOTICE will also be 
thrown if attempting to access a non-existent numerical key in a string, but 
not if attempting to access a non-existent non-numerical key.

If an E_NOTICE is displayed under one circumstance for an index not existing it 
seems that it should be displayed under all circumstances when an index doesn't 
exist.

Reproduce code:
---------------
error_reporting(E_ALL | E_STRICT);

$dummyArray = array();
// this will throw an E_NOTICE
$error = $dummyArray['doesNotExist'];

$dummyArray = true;
// this will not throw an E_NOTICE
$noError = $dummyArray['doesNotExist'];

$dummyArray = 'string';
// this will not throw an E_NOTICE
$noError = $dummyArray['doesNotExist'];
// but this will throw an E_NOTICE
$error = $dummaryArray['100'];


Expected result:
----------------
Notice: Undefined index: doesNotExist
Notice: Undefined index: doesNotExist
Notice: Undefined index: doesNotExist
Notice: Uninitialized string offset:  100

Actual result:
--------------
Notice: Undefined index: doesNotExist
< nothing when attempting to access a non-existent key of a bool >
< nothing when attempting to access a non-existent key of a string >
Notice: Uninitialized string offset:  100


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=45290&edit=1

Reply via email to