- test2: documentation ( source)
<?php
class MyArrayAccess implements \ArrayAccess
{
public function offsetExists($offset)
{
}
public function offsetSet($offset, $value)
{
}
public function offsetGet($offset)
{
}
public function offsetUnset($offset)
{
}
}
function test(array $arr)
{
}
function test2(\ArrayAccess $arr)
{
}
$arrObj = new MyArrayAccess();
test([]); //result: works!
test($arrObj); //result: does NOT work
test2([]); //result: does NOT work
test2($arrObj); // result: works!