From: Dmitry Stogov Date: Wed, 14 Jan 2009 10:28:40 +0000 (+0000) Subject: Reverted "Rebind closure when binding to property" X-Git-Tag: php-5.4.0alpha1~191^2~4523 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7106659cfafa296dc3da5045bbe99adc82b9b386;p=php Reverted "Rebind closure when binding to property" --- diff --git a/Zend/tests/closure_034.phpt b/Zend/tests/closure_034.phpt deleted file mode 100755 index 8a94c7522e..0000000000 --- a/Zend/tests/closure_034.phpt +++ /dev/null @@ -1,233 +0,0 @@ ---TEST-- -Closure 034: var_dump() of a Closure ---FILE-- -func1 = function($param, $other = "default") use ($outer) { - }; - } -} - -$o = new Test; -var_dump($o->func1); - -$o->func2 = function($param, $other = "default") use ($outer) { -}; - -var_dump($o->func2); - -$func3 = function($param, $other = "default") use ($outer) { -}; - -var_dump($func3); - -?> -===DONE=== ---EXPECTF-- -object(Closure)#%d (3) { - ["this"]=> - object(Test)#%d (2) { - [u"func1"]=> - object(Closure)#%d (3) { - ["this"]=> - object(Test)#%d (2) { - [u"func1"]=> - object(Closure)#%d (3) { - ["this"]=> - *RECURSION* - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - [u"var"]=> - int(42) - } - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - [u"var"]=> - int(42) - } - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } -} -object(Closure)#%d (3) { - ["this"]=> - object(Test)#%d (3) { - [u"func1"]=> - object(Closure)#%d (3) { - ["this"]=> - object(Test)#%d (3) { - [u"func1"]=> - object(Closure)#%d (3) { - ["this"]=> - *RECURSION* - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - [u"var"]=> - int(42) - [u"func2"]=> - object(Closure)#%d (3) { - ["this"]=> - *RECURSION* - ["static"]=> - array(1) { - [u"outer"]=> - &int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - } - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - [u"var"]=> - int(42) - [u"func2"]=> - object(Closure)#%d (3) { - ["this"]=> - object(Test)#%d (3) { - [u"func1"]=> - object(Closure)#%d (3) { - ["this"]=> - *RECURSION* - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - [u"var"]=> - int(42) - [u"func2"]=> - object(Closure)#%d (3) { - ["this"]=> - *RECURSION* - ["static"]=> - array(1) { - [u"outer"]=> - &int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - } - ["static"]=> - array(1) { - [u"outer"]=> - &int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } - } - } - ["static"]=> - array(1) { - [u"outer"]=> - &int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } -} -object(Closure)#%d (3) { - ["this"]=> - NULL - ["static"]=> - array(1) { - [u"outer"]=> - int(25) - } - ["parameter"]=> - array(2) { - ["$param"]=> - string(10) "" - ["$other"]=> - string(10) "" - } -} -===DONE=== diff --git a/Zend/tests/closure_035.phpt b/Zend/tests/closure_035.phpt deleted file mode 100755 index ce16611fd7..0000000000 --- a/Zend/tests/closure_035.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -Closure 035: Rebinding closure $this on property access ---FILE-- -instance = ++$instance; - } -} - -$o = new Test; -$o->func = function () { - var_dump($this); -}; -$func = $o->func; -$func(); - -var_dump($instance); -?> -===DONE=== ---EXPECTF-- -object(Test)#%d (2) { - [u"instance"]=> - int(1) - [u"func"]=> - object(Closure)#%d (1) { - ["this"]=> - object(Test)#%d (2) { - [u"instance"]=> - int(1) - [u"func"]=> - object(Closure)#%d (1) { - ["this"]=> - *RECURSION* - } - } - } -} -int(1) -===DONE=== \ No newline at end of file diff --git a/Zend/tests/closure_036.phpt b/Zend/tests/closure_036.phpt deleted file mode 100755 index 301f8601e2..0000000000 --- a/Zend/tests/closure_036.phpt +++ /dev/null @@ -1,29 +0,0 @@ ---TEST-- -Closure 036: Rebinding closure $this on property access, using scope ---FILE-- -instance = ++$instance; - } -} - -$o = new Test; -$o->func = function () { - var_dump($this->value); -}; -$func = $o->func; -$func(); - -var_dump($instance); -?> -===DONE=== ---EXPECTF-- -int(42) -int(1) -===DONE=== \ No newline at end of file diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c index aa4ff21379..2ba3027357 100644 --- a/Zend/zend_closures.c +++ b/Zend/zend_closures.c @@ -122,26 +122,6 @@ ZEND_API zval* zend_get_closure_this_ptr(zval *obj TSRMLS_DC) /* {{{ */ } /* }}} */ -ZEND_API zval* zend_closure_copy(zval *closure_obj, zval *this_ptr TSRMLS_DC) /* {{{ */ -{ - zend_closure *closure; - - zval_copy_ctor(closure_obj); - closure = (zend_closure *)zend_object_store_get_object(closure_obj TSRMLS_CC); - if (closure->this_ptr) { - zval_ptr_dtor(&closure->this_ptr); - } - closure->this_ptr = this_ptr; - if (this_ptr) { - Z_ADDREF_P(this_ptr); - closure->func.common.scope = Z_OBJCE_P(this_ptr); - } else { - closure->func.common.scope = NULL; - } - return closure_obj; -} -/* }}} */ - static zend_function *zend_closure_get_method(zval **object_ptr, zstr method_name, int method_len TSRMLS_DC) /* {{{ */ { unsigned int lc_name_len; diff --git a/Zend/zend_closures.h b/Zend/zend_closures.h index 0358a36bd5..bd0e2c4b4a 100644 --- a/Zend/zend_closures.h +++ b/Zend/zend_closures.h @@ -35,7 +35,6 @@ ZEND_API int zend_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_functio ZEND_API zend_function *zend_get_closure_invoke_method(zval *obj TSRMLS_DC); ZEND_API const zend_function *zend_get_closure_method_def(zval *obj TSRMLS_DC); ZEND_API zval* zend_get_closure_this_ptr(zval *obj TSRMLS_DC); -ZEND_API zval* zend_closure_copy(zval *closure, zval *this_ptr TSRMLS_DC); END_EXTERN_C() diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 576fc652e9..6a093961f8 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -413,10 +413,6 @@ static void zend_std_write_property(zval *object, zval *member, zval *value TSRM member = tmp_member; } - if (value && Z_TYPE_P(value) == IS_OBJECT && Z_OBJCE_P(value) == zend_ce_closure && zend_get_closure_this_ptr(value TSRMLS_CC) != object) { - value = zend_closure_copy(value, object TSRMLS_CC); - } - property_info = zend_get_property_info(zobj->ce, member, (zobj->ce->__set != NULL) TSRMLS_CC); if (property_info && zend_u_hash_quick_find(zobj->properties, Z_TYPE_P(member), property_info->name, property_info->name_length+1, property_info->h, (void **) &variable_ptr) == SUCCESS) {