throw new InvalidArgumentException(sprintf('Item "%s" for "%s" does not exist.', $item, $object));
}
+ // get some information about the object
+ $class = get_class($object);
+ if (!isset($this->cache[$class])) {
+ $r = new ReflectionClass($class);
+ $this->cache[$class] = array();
+ foreach ($r->getMethods(ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_FINAL) as $method) {
+ $this->cache[$class]['methods'][strtolower($method->getName())] = true;
+ }
+
+ foreach ($r->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
+ $this->cache[$class]['properties'][strtolower($property->getName())] = true;
+ }
+ }
+
// object property
if (Twig_Node_Expression_GetAttr::TYPE_METHOD !== $type) {
- if (property_exists($object, $item) || isset($object->$item)) {
+ if (isset($this->cache[$class]['properties'][$item]) || isset($object->$item)) {
if ($this->env->hasExtension('sandbox')) {
$this->env->getExtension('sandbox')->checkPropertyAllowed($object, $item);
}
}
// object method
- $class = get_class($object);
-
- if (!isset($this->cache[$class])) {
- $r = new ReflectionClass($class);
- $this->cache[$class] = array();
- foreach ($r->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_FINAL) as $method) {
- $this->cache[$class][strtolower($method->getName())] = true;
- }
- }
-
$item = strtolower($item);
- if (isset($this->cache[$class][$item])) {
+ if (isset($this->cache[$class]['methods'][$item])) {
$method = $item;
- } elseif (isset($this->cache[$class]['get'.$item])) {
+ } elseif (isset($this->cache[$class]['methods']['get'.$item])) {
$method = 'get'.$item;
- } elseif (isset($this->cache[$class]['__call'])) {
+ } elseif (isset($this->cache[$class]['methods']['__call'])) {
$method = $item;
} else {
if (!$this->env->isStrictVariables()) {
array('bar', $object, 'bar', array(), $methodType),
array('bar', $object, 'getBar', array(), $methodType),
array('foobar', $object, 'foobar', array(), $methodType),
+ array('babar', $object, 'babar', array(), $methodType),
+ array('babarStatic', $object, 'babarStatic', array(), $methodType),
array('__call_baz', $objectMagic, 'baz', array(), $methodType),
// ANY
{
public $foo = 'foo';
public $null = null;
+ protected $babar = 'babar...';
+ static protected $babarStatic = 'babarStatic...';
+
+ static public function getBabarStatic()
+ {
+ return 'babarStatic';
+ }
+
+ public function getBabar()
+ {
+ return 'babar';
+ }
public function getNull()
{