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

[email protected] ("Marcus Boerger")
Newsgroups php.zend-engine.cvs
Message-ID <cvshelly1231006940@cvsserver>
helly		Sat Jan  3 18:22:20 2009 UTC

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

  Modified files:              
    /ZendEngine2	zend_closures.c 
  Log:
  - MFH Fix refcounting
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_closures.c?r1=1.3.2.21&r2=1.3.2.22&diff_format=u
Index: ZendEngine2/zend_closures.c
diff -u ZendEngine2/zend_closures.c:1.3.2.21 ZendEngine2/zend_closures.c:1.3.2.22
--- ZendEngine2/zend_closures.c:1.3.2.21	Sat Jan  3 17:48:39 2009
+++ ZendEngine2/zend_closures.c	Sat Jan  3 18:22:20 2009
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_closures.c,v 1.3.2.21 2009/01/03 17:48:39 helly Exp $ */
+/* $Id: zend_closures.c,v 1.3.2.22 2009/01/03 18:22:20 helly Exp $ */
 
 #include "zend.h"
 #include "zend_API.h"
@@ -124,7 +124,13 @@
 
 	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);
+	}
 	return closure_obj;
 }
 /* }}} */

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

$instance = 0;

class Test {
	function __construct() {
		global $instance;
		$this->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)#2 (1) {
        ["this"]=>
        *RECURSION*
      }
    }
  }
}
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.