I used to get all public vars from a class inside a class with a Closure like this:
Class myClass
{
public $foo;
private $bar;
private function GetFields()
{
$lambda = function( $obj ) { return get_object_vars( $obj ); };
return $lambda( $this );
}
public function SomeFunction()
{
$fields = $this->GetFields();
}
}
This worked perfect, and gave me all public vars while inside a class.
Now, I upgraded my server to PHP 5.4 and I get all privates and protected vars to.
Is that a new ‘Feature’ or is it a Bug?
To answer my own question, its a unwanted side effect of moving closures into the scope of the class.
Have a look at: https://wiki.php.net/rfc/closures/object-extension
In the end I thinks its a bug or at least a unwanted ‘Feature’.
I’ll must think another strategy to find all public properties of a class, while inside a class.
update:
this is what I came up with: