cvs: ZendEngine2 / zend_closures.c /tests closure_020.phpt closure_026.phpt closure_032.phpt

[email protected] ("Marcus Boerger")
Newsgroups php.zend-engine.cvs
Message-ID <cvshelly1230826867@cvsserver>
helly		Thu Jan  1 16:21:07 2009 UTC

  Modified files:              
    /ZendEngine2	zend_closures.c 
    /ZendEngine2/tests	closure_020.phpt closure_026.phpt 
                      	closure_032.phpt 
  Log:
  - Add var_dump support for closures
  
http://cvs.php.net/viewvc.cgi/ZendEngine2/zend_closures.c?r1=1.17&r2=1.18&diff_format=u
Index: ZendEngine2/zend_closures.c
diff -u ZendEngine2/zend_closures.c:1.17 ZendEngine2/zend_closures.c:1.18
--- ZendEngine2/zend_closures.c:1.17	Wed Dec 31 11:12:28 2008
+++ ZendEngine2/zend_closures.c	Thu Jan  1 16:21:07 2009
@@ -14,14 +14,16 @@
    +----------------------------------------------------------------------+
    | Authors: Christian Seiler <[email protected]>                         |
    |          Dmitry Stogov <[email protected]>                             |
+   |          Marcus Boerger <[email protected]>                              |
    +----------------------------------------------------------------------+
 */
 
-/* $Id: zend_closures.c,v 1.17 2008/12/31 11:12:28 sebastian Exp $ */
+/* $Id: zend_closures.c,v 1.18 2009/01/01 16:21:07 helly Exp $ */
 
 #include "zend.h"
 #include "zend_API.h"
 #include "zend_closures.h"
+#include "zend_exceptions.h"
 #include "zend_interfaces.h"
 #include "zend_objects.h"
 #include "zend_objects_API.h"
@@ -226,6 +228,59 @@
 }
 /* }}} */
 
+ZEND_API HashTable *zend_closure_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
+{
+	zend_closure *closure = (zend_closure *)zend_object_store_get_object(object TSRMLS_CC);
+	HashTable *rv;
+	zval *val;
+	struct _zend_arg_info *arg_info = closure->func.common.arg_info;
+
+	*is_temp = 1;
+	ALLOC_HASHTABLE(rv);
+	zend_hash_init(rv, 1, NULL, ZVAL_PTR_DTOR, 0);
+	val = closure->this_ptr;
+	if (!val) {
+		ALLOC_INIT_ZVAL(val);
+	} else {
+		Z_ADDREF_P(val);
+	}
+	zend_symtable_update(rv, "this", sizeof("this"), (void *) &val, sizeof(zval *), NULL);
+	if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) {
+		HashTable *static_variables = closure->func.op_array.static_variables;
+		MAKE_STD_ZVAL(val);
+		array_init(val);
+		zend_hash_copy(Z_ARRVAL_P(val), static_variables, (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval*));
+		zend_symtable_update(rv, "static", sizeof("static"), (void *) &val, sizeof(zval *), NULL);
+	}
+
+	if (arg_info) {
+		MAKE_STD_ZVAL(val);
+		array_init(val);
+		zend_uint i, required = closure->func.common.required_num_args;
+		for (i = 0; i < closure->func.common.num_args; i++) {
+			char *name, *info;
+			int name_len, info_len;
+			if (arg_info->name.v) {
+				name_len = zend_spprintf(&name, 0, "%s$%v",
+								arg_info->pass_by_reference ? "&" : "",
+								arg_info->name.v);
+			} else {
+				name_len = zend_spprintf(&name, 0, "%s$param%d",
+								arg_info->pass_by_reference ? "&" : "",
+								i + 1);
+			}
+			info_len = zend_spprintf(&info, 0, "%s",
+							i >= required ? "<optional>" : "<required>");
+			add_assoc_stringl_ex(val, name, name_len + 1, info, info_len, 0);
+			efree(name);
+			arg_info++;
+		}
+		zend_symtable_update(rv, "parameter", sizeof("parameter"), (void *) &val, sizeof(zval *), NULL);
+	}
+	return rv;
+}
+/* }}} */
+
 void zend_register_closure_ce(TSRMLS_D) /* {{{ */
 {
 	zend_class_entry ce;
@@ -247,6 +302,7 @@
 	closure_handlers.unset_property = zend_closure_unset_property;
 	closure_handlers.compare_objects = zend_closure_compare_objects;
 	closure_handlers.clone_obj = NULL;
+	closure_handlers.get_debug_info = zend_closure_get_debug_info;
 	closure_handlers.get_closure = zend_closure_get_closure;
 }
 /* }}} */
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_020.phpt?r1=1.2&r2=1.3&diff_format=u
Index: ZendEngine2/tests/closure_020.phpt
diff -u ZendEngine2/tests/closure_020.phpt:1.2 ZendEngine2/tests/closure_020.phpt:1.3
--- ZendEngine2/tests/closure_020.phpt:1.2	Mon Jul 14 13:39:32 2008
+++ ZendEngine2/tests/closure_020.phpt	Thu Jan  1 16:21:07 2009
@@ -27,7 +27,40 @@
   [u"test":u"foo":private]=>
   int(3)
   [u"a"]=>
-  object(Closure)#%d (0) {
+  object(Closure)#%d (2) {
+    ["this"]=>
+    object(foo)#%d (2) {
+      [u"test":u"foo":private]=>
+      int(3)
+      [u"a"]=>
+      object(Closure)#%d (2) {
+        ["this"]=>
+        *RECURSION*
+        ["static"]=>
+        array(1) {
+          [u"a"]=>
+          *RECURSION*
+        }
+      }
+    }
+    ["static"]=>
+    array(1) {
+      [u"a"]=>
+      &object(foo)#%d (2) {
+        [u"test":u"foo":private]=>
+        int(3)
+        [u"a"]=>
+        object(Closure)#%d (2) {
+          ["this"]=>
+          *RECURSION*
+          ["static"]=>
+          array(1) {
+            [u"a"]=>
+            *RECURSION*
+          }
+        }
+      }
+    }
   }
 }
 bool(true)
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_026.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_026.phpt
diff -u ZendEngine2/tests/closure_026.phpt:1.1 ZendEngine2/tests/closure_026.phpt:1.2
--- ZendEngine2/tests/closure_026.phpt:1.1	Mon Jul 28 14:09:00 2008
+++ ZendEngine2/tests/closure_026.phpt	Thu Jan  1 16:21:07 2009
@@ -32,7 +32,18 @@
   [u"a"]=>
   array(1) {
     [0]=>
-    object(Closure)#%d (0) {
+    object(Closure)#%d (1) {
+      ["this"]=>
+      object(foo)#%d (1) {
+        [u"a"]=>
+        array(1) {
+          [0]=>
+          object(Closure)#%d (1) {
+            ["this"]=>
+            *RECURSION*
+          }
+        }
+      }
     }
   }
 }
@@ -41,7 +52,21 @@
 unicode(1) "a"
 array(1) {
   [0]=>
-  object(Closure)#%d (0) {
+  object(Closure)#%d (1) {
+    ["this"]=>
+    object(foo)#%d (1) {
+      [u"a"]=>
+      array(1) {
+        [0]=>
+        object(Closure)#%d (1) {
+          ["this"]=>
+          object(foo)#%d (1) {
+            [u"a"]=>
+            *RECURSION*
+          }
+        }
+      }
+    }
   }
 }
 int(1)
http://cvs.php.net/viewvc.cgi/ZendEngine2/tests/closure_032.phpt?r1=1.1&r2=1.2&diff_format=u
Index: ZendEngine2/tests/closure_032.phpt
diff -u ZendEngine2/tests/closure_032.phpt:1.1 ZendEngine2/tests/closure_032.phpt:1.2
--- ZendEngine2/tests/closure_032.phpt:1.1	Mon Nov  3 19:27:48 2008
+++ ZendEngine2/tests/closure_032.phpt	Thu Jan  1 16:21:07 2009
@@ -53,6 +53,12 @@
                 (
                     [0] => Closure Object
                         (
+                            [this] => 
+                            [parameter] => Array
+                                (
+                                    [$param] => <required>
+                                )
+
                         )
 
                 )
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.