|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-03-31 11:56 UTC] mike@php.net
[2006-03-31 12:02 UTC] ante at abstraktmedia dot com
[2007-08-20 16:05 UTC] jausions@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 19:00:01 2025 UTC |
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...