Looks like you can access public, protected, private variables by casting the object to an array (useful for Unit Testing). However casting to an array still won't allow you access to protected and private static variables.
In PHP 5.3.0+ use ReflectionProperty::setAccessable(true);
<?php
echo "PHP Version: ".phpversion()."\n";
class Foo {
public $foo = 'public';
protected $bar = 'protected';
private $baz = 'private';
public static $sfoo = 'public static';
protected static $sbar = 'protected static';
private static $sbaz = 'private static';
const COO = 'const';
}
$obj = new Foo;
$arr = (array)$obj;
print_r($arr);
echo "Accessing Public Static: ".Foo::$sfoo."\n";
echo "Accessing Constant: ".Foo::COO."\n";
?>
PHP Version: 5.2.12
Array
(
[foo] => public
[*bar] => protected
[Foobaz] => private
)
Accessing Public Static: public static
Accessing Constant: const
PHP Version: 5.1.6
Array
(
[foo] => public
[*bar] => protected
[Foobaz] => private
)
Accessing Public Static: public static
Accessing Constant: const