php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28107 Weird string offset E_WARNING behaviour
Submitted: 2004-04-22 13:35 UTC Modified: 2004-04-22 17:20 UTC
From: christian at jul dot net Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.0.0RC1 OS: Debian Linux (sid)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
12 + 48 = ?
Subscribe to this entry?

 
 [2004-04-22 13:35 UTC] christian at jul dot net
Description:
------------
The fact that PHP5 issues an E_WARNING on illegal string offset use, gives a problem on checking values with isset and is_array. Furthermore it does not behave consistent.

Might not be a real bug, since it is the 'Backward Incompatible Changes' list, still the behavior seems to buggy to me.

Reproduce code:
---------------
test.php:
<?php
$a = 'this is not an array';

if(isset($a['foo']))
     print '1';
if(isset($a['foo']['bar']))
     print '2';
if(isset($a['foo']['bar']['doo']))
     print '3';

?>

test2.php
<?php
$a = 'this is not an array';

if(is_array($a['foo']))
     print '1';
if(is_array($a['foo']['bar']))
     print '2';
if(is_array($a['foo']['bar']['doo']))
     print '3';

?>


Expected result:
----------------
Nothing!

Maybe fatal error at line 4 in both scripts, would be ok, but not very niced designed, and doesn't fit well into the type loose scheme of PHP. IMHO.

Actual result:
--------------
Fatal error: Cannot use string offset as an array in
/var/www/sites/test.php on line 8


Fatal error: Cannot use string offset as an array in
/var/www/sites/test2.php on line 6



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-22 17:20 UTC] pollita@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

So don't do that. 
 [2004-04-27 03:36 UTC] aaron dot hawley at uvm dot edu
Why does it only happen with only three or more indexes specified to a variable and not two or one!?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC