From: Operating system: Linux, Redhat Enterprise PHP version: 5.3.5 Package: Arrays related Bug Type: Bug Bug description:isset() and empty() produce apparently spurious runtime error
Description: ------------ First, apologies, this is 5.3.3. I have no means of upgrading to check whether this is a fixed issue. I can't see anything similar in the bug database. An expression of the form isset($obj->m['a']['b']) produces a runtime error when m is not actually an array but a zero length string: Uninitialized string offset: 0 The same is the case if I use empty instead of isset. The same code worked in 5.2. Changing it to isset($obj->m['a']) && isset($obj->m['a']['b']) works. isset is not supposed to produce any runtime error, surely, in this kind of use. The object member values arise from a database lookup, and normally the field (m above) will be a serialized array in the database, but the first time the database column will be empty, leading to an empty string assignment to m. In addition once populated the object is stored in $_SESSION (actually in $_SESSION['p']['q']) and then $obj is obtained by assignment from the session, like this $session =& $_SESSION['p']; // where $_SESSION['p'] is set in a previous page // populate new $obj1 from database $session['q'] = $obj1; ... $obj =& $session['q']; and the offending code is then executed elsewhere some time later. However, abstracting the code from this much bigger program does not demonstrate the problem, which suggests to me something is corrupted somewhere. This is what I tried on its own, which is as close as I can reasonably get to the situation here, but it works. (The =& are leftovers from what was originally a PHP4 app; I know all objects are assigned by reference in PHP5). class c { var $m; } session_start(); if (! isset($_SESSION['p'])) { $_SESSION['p'] = array(); echo "set session array"; exit; } $session =& $_SESSION['p']; $obj1 = new c(); $obj1->m = ''; $session['q'] = $obj1; $obj =& $session['q']; function check() { global $obj; echo (isset($obj->m['a']['b']) ? 'Yes' : 'No'); } check(); Expected result: ---------------- isset to return FALSE Actual result: -------------- runtime error Uninitialized string offset: 0 -- Edit bug report at http://bugs.php.net/bug.php?id=53971&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53971&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53971&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53971&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53971&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53971&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53971&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53971&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53971&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53971&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53971&r=support Expected behavior: http://bugs.php.net/fix.php?id=53971&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53971&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53971&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53971&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53971&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53971&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53971&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53971&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53971&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53971&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53971&r=mysqlcfg