- var_dump: documentation ( source)
- array_merge: documentation ( source)
- array_shift: documentation ( source)
<?php
class A {
public static $p = array(
'abc' => array('test' => array('a')),
'test123' => 'b',
);
}
class B extends A {
public static $p = array(
'abc' => array('test' => array('c')),
'test1' => 'd',
);
public static function mergeRecursive($depth = null)
{
$arrays = func_get_args();
if (!is_array($depth))
array_shift($arrays);
else
$depth = null;
$firstArray = array_shift($arrays);
foreach ($arrays as &$array)
{
if ($depth == 1)
{
$firstArray = array_merge($firstArray, $array);
}
else
{
foreach ($array as $key => &$value)
{
if (is_int($key))
{
$firstArray[] = &$value;
}
else if (isset($firstArray[$key]) && is_array($firstArray[$key]) && is_array($array[$key]))
{
$firstArray[$key] = self::mergeRecursive($depth - 1, $firstArray[$key], $value);
}
else
{
$firstArray[$key] = &$value;
}
}
}
}
return $firstArray;
}
}
var_dump((new ReflectionClass('A'))->getDefaultProperties());
$r = new ReflectionClass('B');
$result = array();
do
{
$result = B::mergeRecursive(2, $r->getDefaultProperties(), $result);
} while($r = $r->getParentClass());
$r = new ReflectionClass('A');
var_dump($r->getDefaultProperties());