mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 04:16:28 +00:00
merged branch arnaud-lb/792 (PR #814)
Commits -------8fa97bbphp5.2 fixd6fc86a[Tests] Test accessing a public property when \ArrayAccess is implemented6704227[ext] made ext consistent with8ec73cf475228d2b0[ext] use only read_property handler Discussion ---------- Alternative fix for 792 This fixes #792 as described in https://github.com/fabpot/Twig/issues/792#issuecomment-7482480 -228d2b0removes the *object-to-array convertion* trick, since the bug comes from there, and it doesn't appear to be needed -6704227is the equivalent ofaa6b835816+8ec73cf475(this were not needed before because the bug was hidden by the object to array trick: numeric strings and integers are treated equally in arrays keys) --------------------------------------------------------------------------- by stof at 2012-08-23T10:19:17Z @arnaud-lb you need to fix the PHP 5.2 support
This commit is contained in:
+10
-14
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user