cvs: ZendEngine2(PHP_5_3) / zend_closures.c /tests closure_036.phpt

[email protected] ("Marcus Boerger") Sun, 04 Jan 2009 14:23:29 -0000
Newsgroups php.zend-engine.cvs
Message-ID <cvshelly1231079009@cvsserver>
helly		Sun Jan  4 14:23:29 2009 UTC

  Added files:                 (Branch: PHP_5_3)
    /ZendEngine2/tests	closure_036.phpt 

  Modified files:              
    /ZendEngine2	zend_closures.c 
  Log:
  - MFH - Set scope when copying a closure with a new this pointer.
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_closures.c?r1=1.3.2.23&r2=1.3.2.24&diff_format=u
Index: ZendEngine2/zend_closures.c
diff -u ZendEngine2/zend_closures.c:1.3.2.23 ZendEngine2/zend_closures.c:1.3.2.24
--- ZendEngine2/zend_closures.c:1.3.2.23	Sat Jan  3 19:29:55 2009
+++ ZendEngine2/zend_closures.c	Sun Jan  4 14:23:29 2009
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_closures.c,v 1.3.2.23 2009/01/03 19:29:55 helly Exp $ */
+/* $Id: zend_closures.c,v 1.3.2.24 2009/01/04 14:23:29 helly Exp $ */
 
 #include "zend.h"
 #include "zend_API.h"
@@ -130,6 +130,9 @@
 	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;
 }

http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_036.phpt?view=markup&rev=1.1
Index: ZendEngine2/tests/closure_036.phpt
+++ ZendEngine2/tests/closure_036.phpt
--TEST--
Closure 036: Rebinding closure $this on property access, using scope
--FILE--
<?php

$instance = 0;

class Test {
	private $value = 42;
	function __construct() {
		global $instance;
		$this->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===