The get_object_vars
function is supposedly scope-sensitive, in that it will only return properties to which it has access to in the current scope.
Given the following crude example, why does the function call return all three properties regardless of their visibility?
<?php
class A
{
private $b = 'foo';
protected $c = 'bar';
public $d = 'baz';
public static function getPublicProperties(\A $object)
{
return get_object_vars($object);
}
}
$a = new \A();
var_dump(\A::getPublicProperties($a));
Result:
array(3) {
'b' =>
string(3) "foo"
'c' =>
string(3) "bar"
'd' =>
string(3) "baz"
}
The getPublicProperties
method is static but is able to access the private and protected properties of the object passed in. Is this a bug in PHP?