note 48083 added to function.is-array

From: Date: Sat, 11 Dec 2004 01:05:24 +0000
Subject: note 48083 added to function.is-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-81667@lists.php.net to get a copy of this message
is_array() under PHP 5.0.2 will return FALSE when passed an object descended from the internal class interface ArrayAccess(http://www.php.net/spl) even though said object behaves as an array would in most instances. I've found the following user function helpful with my own classes and functions that expect array(s) as arguments, but work fine with objects that behave as an array would. <?php function is_array_abled(&$x) { return (bool)($x instanceof ArrayAccess or is_array($x)); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.is-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48083 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48083&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48083&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48083&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48083&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48083&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48083&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48083&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81667) next »