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;
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);
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);
+ }
}
}
/* }}} */
--- /dev/null
+--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===
*** 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