From: Marcus Boerger Date: Sat, 3 Jan 2009 20:41:01 +0000 (+0000) Subject: - MFH Minor corrections and a new test X-Git-Tag: php-5.3.0beta1~284 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c8c0414e174c91842db59b690dfed88a0196483;p=php - MFH Minor corrections and a new test --- diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index d2f5e00e91..74b7cbfb27 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -861,7 +861,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 [ %s $this ]\n", indent, ++index, Z_OBJCE_P(closure_this)->name); + string_printf(str, "%s Parameter #%d [ %s $this ]\n", indent, index++, Z_OBJCE_P(closure_this)->name); } if (static_variables) { HashPosition pos; @@ -869,7 +869,7 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry char* 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 [ $%s ]\n", indent, index++, key); zend_hash_move_forward_ex(static_variables, &pos); @@ -1570,7 +1570,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 index 0000000000..a2bda4feaa --- /dev/null +++ b/ext/reflection/tests/027.phpt @@ -0,0 +1,75 @@ +--TEST-- +--FILE-- +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 [ function {closure} ] { + @@ %s027.php 5 - 7 + + - Static Parameters [2] { + Parameter #0 [ $global ] + Parameter #1 [ $static ] + } + + - Parameters [2] { + Parameter #0 [ $x ] + Parameter #1 [ stdClass or NULL $y = NULL ] + } +} + +NULL +string(9) "{closure}" +bool(true) +Closure [ public method func ] { + @@ %s027.php 21 - 23 + + - Static Parameters [3] { + Parameter #0 [ Test $this ] + Parameter #1 [ $global ] + Parameter #2 [ $static ] + } + + - Parameters [2] { + Parameter #0 [ $x ] + Parameter #1 [ stdClass or NULL $y = NULL ] + } +} + +string(4) "Test" +string(4) "func" +bool(true) +===DONE=== diff --git a/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt b/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt index a54b09de29..6f1e91ea2f 100644 --- a/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt +++ b/ext/reflection/tests/ReflectionMethod_getClosure_error.phpt @@ -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