Voting

: two minus zero?
(Example: nine)

The Note You're Voting On

php5 dot man at lightning dot hu
13 years ago
As you know ArrayObject is not an array so you can't use the built in array functions. Here's a trick around that:

Extend the ArrayObject class with your own and implement this magic method:

<?php
public function __call($func, $argv)
{
if (!
is_callable($func) || substr($func, 0, 6) !== 'array_')
{
throw new
BadMethodCallException(__CLASS__.'->'.$func);
}
return
call_user_func_array($func, array_merge(array($this->getArrayCopy()), $argv));
}
?>

Now you can do this with any array_* function:
<?php
$yourObject
->array_keys();
?>
- Don't forget to ommit the first parameter - it's automatic!

Note: You might want to write your own functions if you're working with large sets of data.

<< Back to user notes page

To Top