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

 ID:                 45290
 Comment by:         bugs dot php dot net at moesen dot nu
 Reported by:        cole dot snodgrass at gmail dot com
 Summary:            always throw an E_NOTICE when accessing an undefined
                     index
 Status:             Open
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   linux
 PHP Version:        5.2.6
 Block user comment: N
 Private report:     N

 New Comment:

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?


Previous Comments:
------------------------------------------------------------------------
[2008-06-17 16:13:01] [email protected]

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 http://bugs.php.net/bug.php?id=45290&edit=1

Reply via email to