PHP Snippet 1:
function get_object_public_vars($object) {
return get_object_vars($object);
}
PHP Snippet 2:
(new ReflectionObject($this))->getProperties(ReflectionProperty::IS_PUBLIC);
PHP Snippet 3:
$publicProperties = call_user_func('get_object_vars', $this);
PHP Snippet 4:
<?php
class Foo {
private $bar = '123';
protected $boo = '456';
public $beer = 'yum';
// return an array of public properties
public function getPublicVars(){
$publicVars = create_function('$obj', 'return get_object_vars($obj);');
return $publicVars($this);
}
}
$foo = new Foo();
$foo->tricky = 'dynamically added var';
$result = $foo->getPublicVars();
print_r($result);