php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28156 E_WARN instead E_ERROR when doing $a = 'asdf'; echo is_array($a['foo']['asdf']
Submitted: 2004-04-26 15:18 UTC Modified: 2012-03-23 17:01 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: info at gramba dot tv Assigned: helly (profile)
Status: Closed Package: *General Issues
PHP Version: 5.0.0.0 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: info at gramba dot tv
New email:
PHP Version: OS:

 

 [2004-04-26 15:18 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-26 20:37 UTC] 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.

 [2007-09-25 11:24 UTC] ofih at fhd dot ko
http://www.meta-fx.com 
forex
 [2012-03-23 17:01 UTC] nikic@php.net
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.
 [2012-03-23 17:01 UTC] nikic@php.net
-Status: Suspended +Status: Closed -Package: Feature/Change Request +Package: *General Issues
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 17:01:35 2025 UTC