From: ante at abstraktmedia dot com Operating system: Win XP PHP version: 5.1.2 PHP Bug Type: SPL related Bug description: Calling is_array on ArrayObject problem (even when casting)
Description: ------------ OK... I'm using ArrayObject quite a lot and I experienced something which is not logical... If I have $arrayObj = new ArrayObject(Array("Test")) function is_array() returns false which is not ok in the first place...but never mind...we'll cast it to array so we use if(is_array((array) $arrayObj)) ..... but the problem is what if $arrayObj is not Array...what if it's null or string? casting to array will make the function return true even if the variable is null.... That's the real problem.... Shor story...I cannot use is_array on ArrayObject if I don't cast that object to a "normal" array..But if I use casting and variable is for example string then is_array will return true when it should return false.... Reproduce code: --------------- Logicaly: $arrayObj = new ArrayObject(Array("Test")); //we don't use casting!! if(is_array($arrayObj)) ... should return TRUE but because of the internal workings of PHP we have to convert ArrayObject to Array before sending it to is_array function... But what if our Array is String actually...??or Null??? Because we HAVE TO cast that ArrayObject before sending it to is_array it will also cast String or anything else to an Array and therefore function will return TRUE... $arrayObj = new ArrayObject(Array("Test")); //$arrayObj = null; if(is_array((array) $arrayObj)) { print("Is array!"); } else { print("Not array!"); } Now try uncommeting second line and commenting first... -- Edit bug report at http://bugs.php.net/?id=36930&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36930&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36930&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36930&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36930&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36930&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36930&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36930&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36930&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36930&r=support Expected behavior: http://bugs.php.net/fix.php?id=36930&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36930&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36930&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36930&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36930&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36930&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36930&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36930&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36930&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36930&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36930&r=mysqlcfg