Bug #54155 [Com]: Insufficient+Inconsistent error reporting

From: Date: Fri, 24 Feb 2012 20:09:23 +0000
Subject: Bug #54155 [Com]: Insufficient+Inconsistent error reporting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-167804@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=54155&edit=1

 ID:                 54155
 Comment by:         robertbasic dot com at gmail dot com
 Reported by:        a1283465 at jnxjn dot com
 Summary:            Insufficient+Inconsistent error reporting
 Status:             Open
 Type:               Bug
 Package:            Variables related
 Operating System:   Linux
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

I'd argue that one should check that a variable is of an expected type, or maybe cast the type
to the expected one, before using it.

I vote for "Not a bug".


Previous Comments:
------------------------------------------------------------------------
[2011-03-03 23:23:32] a1283465 at jnxjn dot com

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



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



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


Thread (5 messages)

« previous php.bugs (#167804) next »