Note: If replacement is not an array, it will be typecast to one (i.e. (array) $parameter). This may result in unexpected behavior when using an object replacement .
Example :
<?php
class A()
{
private $a;
private $b;
public function __construct()
{
$this->a = "foo";
$this->b = "bar";
}
}
$array = array();
array_splice($array, 0, 0, new A());
print_r($array);
?>
Outputs :
Array : Array
{
[0] => foo
[1] => bar
}
Solution : Enforce the array() on the object.
<?php
array_splice($array, 0, 0, array(new Object());
?>
Source : http://bugs.php.net/bug.php?id=44485