]> granicus.if.org Git - php/commitdiff
- Minor corrections and a new test
authorMarcus Boerger <helly@php.net>
Sat, 3 Jan 2009 20:40:22 +0000 (20:40 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 3 Jan 2009 20:40:22 +0000 (20:40 +0000)
ext/reflection/php_reflection.c
ext/reflection/tests/027.phpt [new file with mode: 0755]
ext/reflection/tests/ReflectionMethod_getClosure_error.phpt

index b8b569d5f5ac77dacc841b4cd00cf22c781c66d7..f2ce6aa21d84d593b7c433f964bef2255016f984 100644 (file)
@@ -886,7 +886,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry
                        string_printf(str, "\n");
                        string_printf(str, "%s  - Static Parameters [%d] {\n", indent, count);
                        if (closure_this) {
-                               string_printf(str, "%s    Parameter #%d [ %v $this ]\n", indent, ++index, Z_OBJCE_P(closure_this)->name);
+                               string_printf(str, "%s    Parameter #%d [ %v $this ]\n", indent, index++, Z_OBJCE_P(closure_this)->name);
                        }
                        if (static_variables) {
                                HashPosition pos;
@@ -894,7 +894,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry
                                zstr key;
                                ulong num_index;
                                zend_hash_internal_pointer_reset_ex(static_variables, &pos);
-                               while (index++ < count) {
+                               while (index < count) {
                                        zend_hash_get_current_key_ex(static_variables, &key, &key_len, &num_index, 0, &pos);
                                        string_printf(str, "%s    Parameter #%d [ $%v ]\n", indent, index++, key);
                                        zend_hash_move_forward_ex(static_variables, &pos);
@@ -1605,7 +1605,9 @@ ZEND_METHOD(reflection_function, getClosureThis)
        GET_REFLECTION_OBJECT_PTR(fptr);
        if (intern->obj) {
                closure_this = zend_get_closure_this_ptr(intern->obj TSRMLS_CC);
-               RETURN_ZVAL(closure_this, 1, 0);
+               if (closure_this) {
+                       RETURN_ZVAL(closure_this, 1, 0);
+               }
        }
 }
 /* }}} */
diff --git a/ext/reflection/tests/027.phpt b/ext/reflection/tests/027.phpt
new file mode 100755 (executable)
index 0000000..7839add
--- /dev/null
@@ -0,0 +1,75 @@
+--TEST--
+--FILE--
+<?php
+
+$global = 42;
+
+$func = function($x, stdClass $y=NULL) use($global) {
+       static $static;
+};
+
+ReflectionFunction::Export($func);
+
+$r = new ReflectionFunction($func);
+
+var_dump(@get_class($r->getClosureThis()));
+var_dump($r->getName());
+var_dump($r->isClosure());
+
+Class Test {
+       public $func;
+       function __construct(){
+               global $global;
+               $this->func = function($x, stdClass $y = NULL) use($global) {
+                       static $static;
+               };
+       }
+}
+
+ReflectionMethod::export(new Test, "func");
+
+$r = new ReflectionMethod(new Test, "func");
+
+var_dump(get_class($r->getClosureThis()));
+var_dump($r->getName());
+var_dump($r->isClosure());
+
+?>
+===DONE===
+--EXPECTF--
+Closure [ <user> function {closure} ] {
+  @@ %s027.php 5 - 7
+
+  - Static Parameters [2] {
+    Parameter #0 [ $global ]
+    Parameter #1 [ $static ]
+  }
+
+  - Parameters [2] {
+    Parameter #0 [ <required> $x ]
+    Parameter #1 [ <optional> stdClass or NULL $y = NULL ]
+  }
+}
+
+NULL
+unicode(9) "{closure}"
+bool(true)
+Closure [ <user> public method func ] {
+  @@ %s027.php 21 - 23
+
+  - Static Parameters [3] {
+    Parameter #0 [ Test $this ]
+    Parameter #1 [ $global ]
+    Parameter #2 [ $static ]
+  }
+
+  - Parameters [2] {
+    Parameter #0 [ <required> $x ]
+    Parameter #1 [ <optional> stdClass or NULL $y = NULL ]
+  }
+}
+
+unicode(4) "Test"
+unicode(4) "func"
+bool(true)
+===DONE===
index a54b09de29db8b1782211affef5c7029d210637c..6f1e91ea2fc191b02f08fd2080146dac6e7a3207 100644 (file)
@@ -56,9 +56,13 @@ try {
 *** Testing ReflectionMethod::getClosure() : error conditions ***
 
 -- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --
-object(Closure)#%d (0) {
+object(Closure)#%d (1) {
+  ["this"]=>
+  NULL
 }
-object(Closure)#%d (0) {
+object(Closure)#%d (1) {
+  ["this"]=>
+  NULL
 }
 
 Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 2 given in %s on line %d