Req #28156 [Sus->Csd]: E_WARN instead E_ERROR when doing $a = 'asdf'; echo is_array($a['foo']['asdf']
| From: | nikic@php.net | Date: | Fri, 23 Mar 2012 17:01:25 +0000 |
| Subject: | Req #28156 [Sus->Csd]: E_WARN instead E_ERROR when doing $a = 'asdf'; echo is_array($a['foo']['asdf'] | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168768@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=28156&edit=1
ID: 28156
Updated by: nikic@php.net
Reported by: info at gramba dot tv
Summary: E_WARN instead E_ERROR when doing $a = 'asdf'; echo
is_array($a['foo']['asdf']
-Status: Suspended
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: *
PHP Version: 5.0.0.0
Assigned To: helly
Block user comment: N
Private report: N
New Comment:
In PHP 5.4 this will output:
Warning: Illegal string offset 'foo' in /home/nikic/dev/test.php on line 4
Warning: Illegal string offset 'asdf' in /home/nikic/dev/test.php on line 4
Thus closing.
Previous Comments:
------------------------------------------------------------------------
[2007-09-25 11:24:46] ofih at fhd dot ko
http://www.meta-fx.com
forex
------------------------------------------------------------------------
[2004-04-26 20:37:13] helly@php.net
We are considering a new operator or internal function to take care of this after PHP 5.0. A patch
is here:
http://marcus-boerger.de/php/ext/ze2/ze2-ifsetor-20040416-4.diff.txt
Syntax: ifsetor( <var> [, <exp> ])
Semantic: check whether variable <var> exists and return it. If it not exists evaluate
expression <exp> which defaults to NULL and return that value instead.
Comment: <var> may also be an array subscription of any depth.
------------------------------------------------------------------------
[2004-04-26 15:18:52] info at gramba dot tv
Description:
------------
$a = 'asdf';
echo is_array($a['foo']['asdf']);
is completly invalid, unfortunatly many applications deal with the fact that some offsets simply
"may" not exist.
workaround would be
if (isset($a['foo']['asdf']) &&
is_array($a['foo']['asdf']) {
....
but this would bloat the code a lot
Reproduce code:
---------------
// /* E_ERROR Invalid offset */
$a = 'asdf';
echo is_array($a['foo']['asdf']);
Expected result:
----------------
an E_WARNING instead of E_ERROR which is suppressable
Actual result:
--------------
E_ERROR
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=28156&edit=1