Is there any way this could be achieved?
It's not totally clear what exactly you need (and what your motivation is which would have been good to know to give concrete suggestions), but what you're looking for is possible by using PHP Reflection.
You do so by getting all ancestor classes until the root class, and then you read all properties with it on all these classes. See the ReflectionClass
class with it's ReflectionClass::getDefaultProperties()
method.
See as well
Hope this is helpful, let me know if you run into any problems with that.
<?php
class root {
public $property = 1;
}
class parentClass extends root {
public $ads = FALSE;
}
class child extends parentClass {
public $child = TRUE;
}
$class = 'child';
$chain = array_reverse(class_parents($class), true) + [$class => $class];
$props = [];
foreach($chain as $class)
{
$props += (new ReflectionClass($class))->getDefaultProperties();
}
print_r($props);
Program Output:
Array
(
[property] => 1
[ads] =>
[child] => 1
)