Skip to content

Commit 7c8c041

Browse files
committed
- MFH Minor corrections and a new test
1 parent 4ffc323 commit 7c8c041

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

ext/reflection/php_reflection.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,15 +861,15 @@ static void _function_string(string *str, zend_function *fptr, zend_class_entry
861861
string_printf(str, "\n");
862862
string_printf(str, "%s - Static Parameters [%d] {\n", indent, count);
863863
if (closure_this) {
864-
string_printf(str, "%s Parameter #%d [ %s $this ]\n", indent, ++index, Z_OBJCE_P(closure_this)->name);
864+
string_printf(str, "%s Parameter #%d [ %s $this ]\n", indent, index++, Z_OBJCE_P(closure_this)->name);
865865
}
866866
if (static_variables) {
867867
HashPosition pos;
868868
uint key_len;
869869
char* key;
870870
ulong num_index;
871871
zend_hash_internal_pointer_reset_ex(static_variables, &pos);
872-
while (index++ < count) {
872+
while (index < count) {
873873
zend_hash_get_current_key_ex(static_variables, &key, &key_len, &num_index, 0, &pos);
874874
string_printf(str, "%s Parameter #%d [ $%s ]\n", indent, index++, key);
875875
zend_hash_move_forward_ex(static_variables, &pos);
@@ -1570,7 +1570,9 @@ ZEND_METHOD(reflection_function, getClosureThis)
15701570
GET_REFLECTION_OBJECT_PTR(fptr);
15711571
if (intern->obj) {
15721572
closure_this = zend_get_closure_this_ptr(intern->obj TSRMLS_CC);
1573-
RETURN_ZVAL(closure_this, 1, 0);
1573+
if (closure_this) {
1574+
RETURN_ZVAL(closure_this, 1, 0);
1575+
}
15741576
}
15751577
}
15761578
/* }}} */

ext/reflection/tests/027.phpt

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
--TEST--
2+
--FILE--
3+
<?php
4+
5+
$global = 42;
6+
7+
$func = function($x, stdClass $y=NULL) use($global) {
8+
static $static;
9+
};
10+
11+
ReflectionFunction::Export($func);
12+
13+
$r = new ReflectionFunction($func);
14+
15+
var_dump(@get_class($r->getClosureThis()));
16+
var_dump($r->getName());
17+
var_dump($r->isClosure());
18+
19+
Class Test {
20+
public $func;
21+
function __construct(){
22+
global $global;
23+
$this->func = function($x, stdClass $y = NULL) use($global) {
24+
static $static;
25+
};
26+
}
27+
}
28+
29+
ReflectionMethod::export(new Test, "func");
30+
31+
$r = new ReflectionMethod(new Test, "func");
32+
33+
var_dump(get_class($r->getClosureThis()));
34+
var_dump($r->getName());
35+
var_dump($r->isClosure());
36+
37+
?>
38+
===DONE===
39+
--EXPECTF--
40+
Closure [ <user> function {closure} ] {
41+
@@ %s027.php 5 - 7
42+
43+
- Static Parameters [2] {
44+
Parameter #0 [ $global ]
45+
Parameter #1 [ $static ]
46+
}
47+
48+
- Parameters [2] {
49+
Parameter #0 [ <required> $x ]
50+
Parameter #1 [ <optional> stdClass or NULL $y = NULL ]
51+
}
52+
}
53+
54+
NULL
55+
string(9) "{closure}"
56+
bool(true)
57+
Closure [ <user> public method func ] {
58+
@@ %s027.php 21 - 23
59+
60+
- Static Parameters [3] {
61+
Parameter #0 [ Test $this ]
62+
Parameter #1 [ $global ]
63+
Parameter #2 [ $static ]
64+
}
65+
66+
- Parameters [2] {
67+
Parameter #0 [ <required> $x ]
68+
Parameter #1 [ <optional> stdClass or NULL $y = NULL ]
69+
}
70+
}
71+
72+
string(4) "Test"
73+
string(4) "func"
74+
bool(true)
75+
===DONE===

ext/reflection/tests/ReflectionMethod_getClosure_error.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,13 @@ try {
5656
*** Testing ReflectionMethod::getClosure() : error conditions ***
5757

5858
-- Testing ReflectionMethod::getClosure() function with more than expected no. of arguments --
59-
object(Closure)#%d (0) {
59+
object(Closure)#%d (1) {
60+
["this"]=>
61+
NULL
6062
}
61-
object(Closure)#%d (0) {
63+
object(Closure)#%d (1) {
64+
["this"]=>
65+
NULL
6266
}
6367

6468
Warning: ReflectionMethod::getClosure() expects exactly 1 parameter, 2 given in %s on line %d

0 commit comments

Comments
 (0)