From: Michael Wallner Date: Thu, 22 Jan 2015 16:18:04 +0000 (+0100) Subject: use zend_string; add test X-Git-Tag: release-2.0.0RC1~19 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=e06c08bbfab4933e79569513eb3218dab8c3d521;p=m6w6%2Fext-propro use zend_string; add test --- diff --git a/php_propro.c b/php_propro.c index 090b0da..ac4d973 100644 --- a/php_propro.c +++ b/php_propro.c @@ -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 index 0000000..886e220 --- /dev/null +++ b/tests/003.phpt @@ -0,0 +1,41 @@ +--TEST-- +property proxy +--SKIPIF-- + +--FILE-- +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