diff --git a/ext/twig/twig.c b/ext/twig/twig.c index 71084a48b..f8fc8592d 100644 --- a/ext/twig/twig.c +++ b/ext/twig/twig.c @@ -288,22 +288,8 @@ zval *TWIG_GET_ARRAY_ELEMENT(zval *class, char *prop_name, int prop_name_length zval *TWIG_PROPERTY(zval *object, zval *propname TSRMLS_DC) { - char *prot_name; - int prot_name_length; zval *tmp = NULL; - tmp = TWIG_GET_ARRAY_ELEMENT(object, Z_STRVAL_P(propname), Z_STRLEN_P(propname) TSRMLS_CC); - if (tmp) { - return tmp; - } - - zend_mangle_property_name(&prot_name, &prot_name_length, "*", 1, Z_STRVAL_P(propname), Z_STRLEN_P(propname), 0); - tmp = TWIG_GET_ARRAY_ELEMENT(object, prot_name, prot_name_length TSRMLS_CC); - efree(prot_name); - if (tmp) { - return tmp; - } - if (Z_OBJ_HT_P(object)->read_property) { #if PHP_VERSION_ID >= 50400 tmp = Z_OBJ_HT_P(object)->read_property(object, propname, BP_VAR_IS, NULL TSRMLS_CC); @@ -698,6 +684,16 @@ PHP_FUNCTION(twig_template_get_attributes) INIT_PZVAL(&zitem); ZVAL_STRINGL(&zitem, item, item_len, 0); + switch (is_numeric_string(item, item_len, &Z_LVAL(zitem), &Z_DVAL(zitem), 0)) { + case IS_LONG: + Z_TYPE(zitem) = IS_LONG; + break; + case IS_DOUBLE: + Z_TYPE(zitem) = IS_DOUBLE; + convert_to_long(&zitem); + break; + } + if (!type) { type = "any"; } diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 4213e2b65..9c5b909ee 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -102,6 +102,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase $magicPropertyObject = new Twig_TemplateMagicPropertyObject(); $propertyObject = new Twig_TemplatePropertyObject(); $propertyObject1 = new Twig_TemplatePropertyObjectAndIterator(); + $propertyObject2 = new Twig_TemplatePropertyObjectAndArrayAccess(); $methodObject = new Twig_TemplateMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject(); @@ -129,6 +130,7 @@ class Twig_Tests_TemplateTest extends PHPUnit_Framework_TestCase array($methodObject, $anyType), array($propertyObject, $anyType), array($propertyObject1, $anyType), + array($propertyObject2, $anyType), ); $tests = array(); @@ -318,6 +320,29 @@ class Twig_TemplatePropertyObjectAndIterator extends Twig_TemplatePropertyObject } } +class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObject implements ArrayAccess +{ + private $data = array(); + + public function offsetExists($offset) + { + return array_key_exists($offset, $this->data); + } + + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->data[$offset] : 'n/a'; + } + + public function offsetSet($offset, $value) + { + } + + public function offsetUnset($offset) + { + } +} + class Twig_TemplateMethodObject { public function getDefined()