<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
class Foo extends ArrayObject
{
public $foo = 'foo';
public function getBar()
{
return 'bar';
}
// Same name: method over property
public $baz = 'baz1';
public function getBaz()
{
return 'baz2';
}
// access arrays
public $qux = ['key' => 'value'];
// chaining
public function getMe()
{
return $this;
}
}
$foo = new Foo();
$accessor = PropertyAccess::createPropertyAccessor();
echo $accessor->getValue($foo, 'foo') . PHP_EOL;
echo $accessor->getValue($foo, 'bar') . PHP_EOL;
echo $accessor->getValue($foo, 'baz') . PHP_EOL;
echo $accessor->getValue($foo, 'qux[key]') . PHP_EOL;
echo $accessor->getValue($foo, 'me.qux[key]') . PHP_EOL;