<?php
class Foo
{
public $bar = 'bar';
public $baz = 'baz';
}
class FooHack extends Foo
{
public function __construct(Foo $wrapped)
{
unset($this->bar);
}
}
$foo = new FooHack(new Foo);
$reflectionFooBar = new \ReflectionProperty(Foo::class, 'bar');
var_dump((new ReflectionClass(Foo::class))->getProperties());
var_dump($reflectionFooBar->getValue($foo));
var_dump(
property_exists(FooHack::class, 'bar'),
property_exists($foo, 'bar')
);
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
- array(2) {
[0]=>
object(ReflectionProperty)#4 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(3) "Foo"
}
[1]=>
object(ReflectionProperty)#5 (2) {
["name"]=>
string(3) "baz"
["class"]=>
string(3) "Foo"
}
}
Warning: Undefined property: FooHack::$bar in /in/VDMHm on line 21
NULL
bool(true)
bool(true)
- Output for 7.0.7 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
- array(2) {
[0]=>
object(ReflectionProperty)#4 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(3) "Foo"
}
[1]=>
object(ReflectionProperty)#5 (2) {
["name"]=>
string(3) "baz"
["class"]=>
string(3) "Foo"
}
}
Notice: Undefined property: FooHack::$bar in /in/VDMHm on line 21
NULL
bool(true)
bool(true)
- Output for 7.0.0 - 7.0.6, 7.3.32 - 7.3.33
- array(2) {
[0]=>
object(ReflectionProperty)#4 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(3) "Foo"
}
[1]=>
object(ReflectionProperty)#5 (2) {
["name"]=>
string(3) "baz"
["class"]=>
string(3) "Foo"
}
}
NULL
bool(true)
bool(true)
- Output for 5.6.0 - 5.6.30
- array(2) {
[0]=>
&object(ReflectionProperty)#4 (2) {
["name"]=>
string(3) "bar"
["class"]=>
string(3) "Foo"
}
[1]=>
&object(ReflectionProperty)#5 (2) {
["name"]=>
string(3) "baz"
["class"]=>
string(3) "Foo"
}
}
NULL
bool(true)
bool(true)
preferences:
147.1 ms | 411 KiB | 5 Q