Bug #55032 [Com]: Treating null, boolean and numbers as arrays does not trigger an error
| From: | cagret at gmail dot com | Date: | Tue, 14 Jun 2011 15:26:35 +0000 |
| Subject: | Bug #55032 [Com]: Treating null, boolean and numbers as arrays does not trigger an error | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-161390@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=55032&edit=1
ID: 55032
Comment by: cagret at gmail dot com
Reported by: cagret at gmail dot com
Summary: Treating null, boolean and numbers as arrays does
not trigger an error
Status: Duplicate
Type: Bug
Package: Variables related
Operating System: Linux, Windows
PHP Version: 5.3.6
Block user comment: N
Private report: N
New Comment:
What is the logic of keeping this bug as intended behavior? You do the opposite
thing to undefined array indexes by showing an error, but here you do not do such
thing. What is worse is that $array['no_such_key'] is a valid code even if there
is no such key, but $true['asdf'] where $true is a boolean is just nonsense.
Do you want some real life examples of why this behavior generates many of bugs in
our code and makes our life harder? Do you even understand the problem?
Previous Comments:
------------------------------------------------------------------------
[2011-06-14 17:15:55] cagret at gmail dot com
Thank you for reading my comment with understanding.
We have an option to ignore/show E_NOTICE errors of undefined array indexes by
setting error_reporting, why can't we have an option for not ignoring this
behaviour? That could be easily fixed with no problems to backward compatibility,
making it a behavior of E_STRICT or we could add an another E_ option for this.
------------------------------------------------------------------------
[2011-06-14 15:51:14] aharvey@php.net
This is intended behaviour, per bug #41195.
------------------------------------------------------------------------
[2011-06-13 19:14:44] cagret at gmail dot com
If implementing it is a performance problem (can't think of any other reason why it still
hasn't been fixed), then you could at least give us an
option, for example a php.ini option "check_types" that would be checking for such error.
That would allow us to enable this option on Developer
machines during testings and hopefully we would catch and fix all of these errors before uploading
the code to the Production machine.
------------------------------------------------------------------------
[2011-06-11 02:19:47] cagret at gmail dot com
Description:
------------
This bug is really annoying and generates many headeaches to millions of php
developers. It's really hard to detect this bug sometimes, and that is because
we have so much faith in PHP and we think that it's not possible that php would
allow us to write such a nonsensical code and not throw an error, after all
didn't we set the most strict error reporting you allow us to set?
This example code should be self explanatory:
<?php
error_reporting(-1); // The most strict error reporting.
$n = null;
echo $n[12]; // That should generate at least a E_NOTICE or E_STRICT warning.
$f = false;
echo $f[12]; // No error.
$t = true;
echo $t[12]; // No error, again.
$a = 4;
echo $a[12]; // Oh really, again no error? What a surprise!
$a = 4.44;
echo $a[12]; // And what do you think?! Guess! No error!
?>
Please fix it ASAP.
Thank you for your time.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=55032&edit=1