use zend_string; add test
authorMichael Wallner <mike@php.net>
Thu, 22 Jan 2015 16:18:04 +0000 (17:18 +0100)
committerMichael Wallner <mike@php.net>
Thu, 22 Jan 2015 16:18:04 +0000 (17:18 +0100)
php_propro.c
tests/003.phpt [new file with mode: 0644]

index 090b0dabe8e868e55a32acab7ddbd7003156a2f7..ac4d973dfabced6ad519b9d67d151eeffcf7c02a 100644 (file)
@@ -354,7 +354,7 @@ static void set_proxied_value(zval *object, zval *value)
 static zval *read_dimension(zval *object, zval *offset, int type, zval *return_value)
 {
        zval proxied_value;
-       zval *o = offset;
+       zend_string *member = offset ? zval_get_string(offset) : NULL;
 
        debug_propro(1, type == BP_VAR_R ? "dim_read" : "dim_read_ref",
                        get_propro(object), offset, NULL);
@@ -362,21 +362,16 @@ static zval *read_dimension(zval *object, zval *offset, int type, zval *return_v
        ZVAL_UNDEF(&proxied_value);
        get_proxied_value(object, &proxied_value);
 
-       if (o) {
-               convert_to_string_ex(o);
-       }
-
-       if (BP_VAR_R == type && o && !Z_ISUNDEF(proxied_value)) {
+       if (BP_VAR_R == type && member && !Z_ISUNDEF(proxied_value)) {
                if (Z_TYPE(proxied_value) == IS_ARRAY) {
                        zval *hash_value = zend_symtable_find(Z_ARRVAL(proxied_value),
-                                       Z_STR_P(o));
+                                       member);
 
                        if (hash_value) {
                                RETVAL_ZVAL(hash_value, 1, 0);
                        }
                }
        } else {
-               zend_string *member;
                php_property_proxy_t *proxy;
                php_property_proxy_object_t *proxy_obj;
 
@@ -388,9 +383,7 @@ static zval *read_dimension(zval *object, zval *offset, int type, zval *return_v
                        set_proxied_value(object, &proxied_value);
                }
 
-               if (o) {
-                       member = Z_STR_P(o);
-               } else {
+               if (!member) {
                        member = zend_long_to_str(zend_hash_next_free_element(
                                        Z_ARRVAL(proxied_value)));
                }
@@ -398,17 +391,13 @@ static zval *read_dimension(zval *object, zval *offset, int type, zval *return_v
                proxy = php_property_proxy_init(&proxied_value, member);
                zval_ptr_dtor(&proxied_value);
 
-               if (!o) {
-                       zend_string_release(member);
-               }
-
                proxy_obj = php_property_proxy_object_new_ex(NULL, proxy);
                ZVAL_COPY(&proxy_obj->parent, object);
                RETVAL_OBJ(&proxy_obj->zo);
        }
 
-       if (o && o != offset) {
-               zval_ptr_dtor(o);
+       if (member) {
+               zend_string_release(member);
        }
 
        debug_propro(-1, type == BP_VAR_R ? "dim_read" : "dim_read_ref",
diff --git a/tests/003.phpt b/tests/003.phpt
new file mode 100644 (file)
index 0000000..886e220
--- /dev/null
@@ -0,0 +1,41 @@
+--TEST--
+property proxy
+--SKIPIF--
+<?php 
+extension_loaded("propro") || print "skip";
+?>
+--FILE--
+<?php 
+echo "Test\n";
+
+class t {
+       private $ref;
+       function __get($v) {
+               return new php\PropertyProxy($this, $v);
+       } 
+}
+
+$t = new t;
+$r = &$t->ref;
+$r = 1;
+var_dump($t);
+$t->ref[] = 2;
+var_dump($t);
+?>
+===DONE===
+--EXPECTF--
+Test
+object(t)#%d (1) {
+  ["ref":"t":private]=>
+  int(1)
+}
+object(t)#%d (1) {
+  ["ref":"t":private]=>
+  array(2) {
+    [0]=>
+    int(1)
+    [1]=>
+    int(2)
+  }
+}
+===DONE===
\ No newline at end of file