cvs: ZendEngine2 / zend_closures.c /tests closure_036.phpt

[email protected] ("Marcus Boerger")
Newsgroups php.zend-engine.cvs
Message-ID <cvshelly1231078972@cvsserver>
helly		Sun Jan  4 14:22:52 2009 UTC

  Added files:                 
    /ZendEngine2/tests	closure_036.phpt 

  Modified files:              
    /ZendEngine2	zend_closures.c 
  Log:
  - Set scope when copying a closure with a new this pointer.
  
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_closures.c?r1=1.24&r2=1.25&diff_format=u
Index: ZendEngine2/zend_closures.c
diff -u ZendEngine2/zend_closures.c:1.24 ZendEngine2/zend_closures.c:1.25
--- ZendEngine2/zend_closures.c:1.24	Sat Jan  3 19:29:04 2009
+++ ZendEngine2/zend_closures.c	Sun Jan  4 14:22:51 2009
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_closures.c,v 1.24 2009/01/03 19:29:04 helly Exp $ */
+/* $Id: zend_closures.c,v 1.25 2009/01/04 14:22:51 helly Exp $ */
 
 #include "zend.h"
 #include "zend_API.h"
@@ -134,6 +134,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===
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.