Skip to content

Commit

Permalink
- Minor corrections and a new test
Browse files Browse the repository at this point in the history
  • Loading branch information
helly25 committed Jan 3, 2009
1 parent 30647d3 commit 21b49d9
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
8 changes: 5 additions & 3 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,15 +886,15 @@ 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;
uint key_len;
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);
Expand Down Expand Up @@ -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);
}
}
}
/* }}} */
Expand Down
75 changes: 75 additions & 0 deletions ext/reflection/tests/027.phpt
Original file line number Diff line number Diff line change
@@ -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===
8 changes: 6 additions & 2 deletions ext/reflection/tests/ReflectionMethod_getClosure_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21b49d9

Please sign in to comment.