// object property
if (Twig_TemplateInterface::METHOD_CALL !== $type) {
+ /* apparently, this is not needed as this is already covered by the array_key_exists() call below
if (!isset(self::$cache[$class]['properties'])) {
- $props = get_object_vars($object);
- foreach ($props as &$v) {
- $v = true;
+ foreach (get_object_vars($object) as $k => $v) {
+ self::$cache[$class]['properties'][$k] = true;
}
- self::$cache[$class]['properties'] = $props;
}
+ */
- if (isset(self::$cache[$class]['properties'][$item])
- || isset($object->$item) || array_key_exists($item, $object)
- ) {
+ if (isset($object->$item) || array_key_exists($item, $object)) {
if ($isDefinedTest) {
return true;
}
'1' => 1,
);
- $objectArray = new Twig_TemplateArrayAccessObject;
+ $objectArray = new Twig_TemplateArrayAccessObject();
$stdObject = (object) $array;
- $magicPropertyObject = new Twig_TemplateMagicPropertyObject;
- $methodObject = new Twig_TemplateMethodObject;
- $magicMethodObject = new Twig_TemplateMagicMethodObject;
+ $magicPropertyObject = new Twig_TemplateMagicPropertyObject();
+ $propertyObject = new Twig_TemplatePropertyObject();
+ $propertyObject1 = new Twig_TemplatePropertyObjectAndIterator();
+ $methodObject = new Twig_TemplateMethodObject();
+ $magicMethodObject = new Twig_TemplateMagicMethodObject();
$anyType = Twig_TemplateInterface::ANY_CALL;
$methodType = Twig_TemplateInterface::METHOD_CALL;
// array(defined, value, property to fetch)
array(true, 'defined', 'defined'),
array(false, null, 'undefined'),
+ array(false, null, 'protected'),
array(true, 0, 'zero'),
array(true, 1, 1),
array(true, 1, 1.0),
array($stdObject, $anyType),
array($magicPropertyObject, $anyType),
array($methodObject, $methodType),
+ array($propertyObject, $anyType),
+ array($propertyObject1, $anyType),
);
$tests = array();
foreach ($testObjects as $testObject) {
foreach ($basicTests as $test) {
// properties cannot be numbers
- if ($testObject[0] instanceof stdClass && is_numeric($test[2])) {
+ if (($testObject[0] instanceof stdClass || $testObject[0] instanceof Twig_TemplatePropertyObject) && is_numeric($test[2])) {
continue;
}
class Twig_TemplateArrayAccessObject implements ArrayAccess
{
+ protected $protected = 'protected';
+
public $attributes = array(
'defined' => 'defined',
'zero' => 0,
class Twig_TemplateMagicPropertyObject
{
+ public $defined = 'defined';
+
public $attributes = array(
- 'defined' => 'defined',
'zero' => 0,
'null' => null,
'1' => 1,
);
+ protected $protected = 'protected';
+
public function __isset($name)
{
return array_key_exists($name, $this->attributes);
}
}
+class Twig_TemplatePropertyObject
+{
+ public $defined = 'defined';
+ public $zero = 0;
+ public $null = null;
+
+ protected $protected = 'protected';
+}
+
+class Twig_TemplatePropertyObjectAndIterator extends Twig_TemplatePropertyObject implements IteratorAggregate
+{
+ public function getIterator()
+ {
+ return new ArrayIterator(array('foo', 'bar'));
+ }
+}
+
class Twig_TemplateMethodObject
{
public function getDefined()
return null;
}
+ protected function getProtected()
+ {
+ return 'protected';
+ }
+
static public function getStatic()
{
return 'static';