diff options
| author | Felipe Pena <felipe@php.net> | 2010-06-11 23:37:55 +0000 |
|---|---|---|
| committer | Felipe Pena <felipe@php.net> | 2010-06-11 23:37:55 +0000 |
| commit | 4d3944f9411a495a53807ae57f34db9dec54372b (patch) | |
| tree | 87852903b4e43d0d3b91c1aac486dca8ef88597c /ext | |
| parent | 5eb64a49576a0768dcffce52f92af7207f300d04 (diff) | |
| download | php-git-4d3944f9411a495a53807ae57f34db9dec54372b.tar.gz | |
- Fixed bug #52057 (ReflectionClass fails on Closure class)
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/reflection/php_reflection.c | 13 | ||||
| -rw-r--r-- | ext/reflection/tests/bug52057.phpt | 54 |
2 files changed, 66 insertions, 1 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a323e5e15d..1f42a7e0a6 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3384,7 +3384,9 @@ ZEND_METHOD(reflection_class, hasMethod) GET_REFLECTION_OBJECT_PTR(ce); lc_name = zend_str_tolower_dup(name, name_len); - if (zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) { + if ((ce == zend_ce_closure && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0) + || zend_hash_exists(&ce->function_table, lc_name, name_len + 1)) { efree(lc_name); RETURN_TRUE; } else { @@ -3401,6 +3403,7 @@ ZEND_METHOD(reflection_class, getMethod) reflection_object *intern; zend_class_entry *ce; zend_function *mptr; + zval obj_tmp; char *name, *lc_name; int name_len; @@ -3419,6 +3422,14 @@ ZEND_METHOD(reflection_class, getMethod) method and not the closure definition itself */ reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); + } else if (ce == zend_ce_closure && !intern->obj && (name_len == sizeof(ZEND_INVOKE_FUNC_NAME)-1) + && memcmp(lc_name, ZEND_INVOKE_FUNC_NAME, sizeof(ZEND_INVOKE_FUNC_NAME)-1) == 0 + && object_init_ex(&obj_tmp, ce) == SUCCESS && (mptr = zend_get_closure_invoke_method(&obj_tmp TSRMLS_CC)) != NULL) { + /* don't assign closure_object since we only reflect the invoke handler + method and not the closure definition itself */ + reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); + zval_dtor(&obj_tmp); + efree(lc_name); } else if (zend_hash_find(&ce->function_table, lc_name, name_len + 1, (void**) &mptr) == SUCCESS) { reflection_method_factory(ce, mptr, NULL, return_value TSRMLS_CC); efree(lc_name); diff --git a/ext/reflection/tests/bug52057.phpt b/ext/reflection/tests/bug52057.phpt new file mode 100644 index 0000000000..b807035718 --- /dev/null +++ b/ext/reflection/tests/bug52057.phpt @@ -0,0 +1,54 @@ +--TEST-- +Bug #52057 (ReflectionClass fails on Closure class) +--FILE-- +<?php + +$closure = function($a) { echo $a; }; + +$reflection = new ReflectionClass('closure'); +var_dump($reflection->hasMethod('__invoke')); // true + +$reflection = new ReflectionClass($closure); +var_dump($reflection->hasMethod('__invoke')); // true + +$reflection = new ReflectionObject($closure); +var_dump($reflection->hasMethod('__invoke')); // true + +$reflection = new ReflectionClass('closure'); +var_dump($h = $reflection->getMethod('__invoke')); // true +var_dump($h->class.'::'.$h->getName()); + +$reflection = new ReflectionClass($closure); +var_dump($h = $reflection->getMethod('__invoke')); // true +var_dump($h->class.'::'.$h->getName()); + +$reflection = new ReflectionObject($closure); +var_dump($h = $reflection->getMethod('__invoke')); // true +var_dump($h->class.'::'.$h->getName()); + +?> +--EXPECTF-- +bool(true) +bool(true) +bool(true) +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(8) "__invoke" + ["class"]=> + string(7) "Closure" +} +string(17) "Closure::__invoke" +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(8) "__invoke" + ["class"]=> + string(7) "Closure" +} +string(17) "Closure::__invoke" +object(ReflectionMethod)#%d (2) { + ["name"]=> + string(8) "__invoke" + ["class"]=> + string(7) "Closure" +} +string(17) "Closure::__invoke" |
