diff options
Diffstat (limited to 'ext/reflection')
| -rw-r--r-- | ext/reflection/php_reflection.c | 65 | ||||
| -rw-r--r-- | ext/reflection/php_reflection.h | 2 | ||||
| -rw-r--r-- | ext/reflection/tests/005.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/009.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/025.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionClass_getDocComment_001.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionFunction_isGenerator_basic.phpt | 52 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionProperty_basic2.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/bug36308.phpt | 3 | ||||
| -rw-r--r-- | ext/reflection/tests/bug64007.phpt | 19 |
13 files changed, 143 insertions, 22 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f6367cdb4e..e6cef1dfed 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2014 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -3084,6 +3084,14 @@ ZEND_METHOD(reflection_function, isDeprecated) } /* }}} */ +/* {{{ proto public bool ReflectionFunction::isGenerator() + Returns whether this function is a generator */ +ZEND_METHOD(reflection_function, isGenerator) +{ + _function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_GENERATOR); +} +/* }}} */ + /* {{{ proto public bool ReflectionFunction::inNamespace() Returns whether this function is defined in namespace */ ZEND_METHOD(reflection_function, inNamespace) @@ -4182,32 +4190,40 @@ ZEND_METHOD(reflection_class, newInstance) { zval *retval_ptr = NULL; reflection_object *intern; - zend_class_entry *ce; + zend_class_entry *ce, *old_scope; + zend_function *constructor; METHOD_NOTSTATIC(reflection_class_ptr); GET_REFLECTION_OBJECT_PTR(ce); + object_init_ex(return_value, ce); + + old_scope = EG(scope); + EG(scope) = ce; + constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC); + EG(scope) = old_scope; + /* Run the constructor if there is one */ - if (ce->constructor) { + if (constructor) { zval ***params = NULL; int num_args = 0; zend_fcall_info fci; zend_fcall_info_cache fcc; - if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { + if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name); - return; + zval_dtor(return_value); + RETURN_NULL(); } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "*", ¶ms, &num_args) == FAILURE) { if (params) { efree(params); } + zval_dtor(return_value); RETURN_FALSE; } - object_init_ex(return_value, ce); - fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = NULL; @@ -4219,7 +4235,7 @@ ZEND_METHOD(reflection_class, newInstance) fci.no_separation = 1; fcc.initialized = 1; - fcc.function_handler = ce->constructor; + fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object_ptr = return_value; @@ -4232,6 +4248,7 @@ ZEND_METHOD(reflection_class, newInstance) zval_ptr_dtor(&retval_ptr); } php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name); + zval_dtor(return_value); RETURN_NULL(); } if (retval_ptr) { @@ -4240,9 +4257,7 @@ ZEND_METHOD(reflection_class, newInstance) if (params) { efree(params); } - } else if (!ZEND_NUM_ARGS()) { - object_init_ex(return_value, ce); - } else { + } else if (ZEND_NUM_ARGS()) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); } } @@ -4272,9 +4287,10 @@ ZEND_METHOD(reflection_class, newInstanceArgs) { zval *retval_ptr = NULL; reflection_object *intern; - zend_class_entry *ce; + zend_class_entry *ce, *old_scope; int argc = 0; HashTable *args; + zend_function *constructor; METHOD_NOTSTATIC(reflection_class_ptr); @@ -4283,19 +4299,28 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|h", &args) == FAILURE) { return; } + if (ZEND_NUM_ARGS() > 0) { argc = args->nNumOfElements; } + object_init_ex(return_value, ce); + + old_scope = EG(scope); + EG(scope) = ce; + constructor = Z_OBJ_HT_P(return_value)->get_constructor(return_value TSRMLS_CC); + EG(scope) = old_scope; + /* Run the constructor if there is one */ - if (ce->constructor) { + if (constructor) { zval ***params = NULL; zend_fcall_info fci; zend_fcall_info_cache fcc; - if (!(ce->constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { + if (!(constructor->common.fn_flags & ZEND_ACC_PUBLIC)) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Access to non-public constructor of class %s", ce->name); - return; + zval_dtor(return_value); + RETURN_NULL(); } if (argc) { @@ -4304,8 +4329,6 @@ ZEND_METHOD(reflection_class, newInstanceArgs) params -= argc; } - object_init_ex(return_value, ce); - fci.size = sizeof(fci); fci.function_table = EG(function_table); fci.function_name = NULL; @@ -4317,7 +4340,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) fci.no_separation = 1; fcc.initialized = 1; - fcc.function_handler = ce->constructor; + fcc.function_handler = constructor; fcc.calling_scope = EG(scope); fcc.called_scope = Z_OBJCE_P(return_value); fcc.object_ptr = return_value; @@ -4330,6 +4353,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) zval_ptr_dtor(&retval_ptr); } php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invocation of %s's constructor failed", ce->name); + zval_dtor(return_value); RETURN_NULL(); } if (retval_ptr) { @@ -4338,9 +4362,7 @@ ZEND_METHOD(reflection_class, newInstanceArgs) if (params) { efree(params); } - } else if (!ZEND_NUM_ARGS() || !argc) { - object_init_ex(return_value, ce); - } else { + } else if (argc) { zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ce->name); } } @@ -5683,6 +5705,7 @@ static const zend_function_entry reflection_function_abstract_functions[] = { ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0) ZEND_ME(reflection_function, isInternal, arginfo_reflection__void, 0) ZEND_ME(reflection_function, isUserDefined, arginfo_reflection__void, 0) + ZEND_ME(reflection_function, isGenerator, arginfo_reflection__void, 0) ZEND_ME(reflection_function, getClosureThis, arginfo_reflection__void, 0) ZEND_ME(reflection_function, getClosureScopeClass, arginfo_reflection__void, 0) ZEND_ME(reflection_function, getDocComment, arginfo_reflection__void, 0) diff --git a/ext/reflection/php_reflection.h b/ext/reflection/php_reflection.h index 2c03bd6e7e..48470f4f63 100644 --- a/ext/reflection/php_reflection.h +++ b/ext/reflection/php_reflection.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2014 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | diff --git a/ext/reflection/tests/005.phpt b/ext/reflection/tests/005.phpt index f337e44ae6..e257699b6f 100644 --- a/ext/reflection/tests/005.phpt +++ b/ext/reflection/tests/005.phpt @@ -1,5 +1,8 @@ --TEST-- ReflectionMethod::getDocComment() uses wrong comment block +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/009.phpt b/ext/reflection/tests/009.phpt index e96b21ebaf..b54e89e5bf 100644 --- a/ext/reflection/tests/009.phpt +++ b/ext/reflection/tests/009.phpt @@ -1,5 +1,8 @@ --TEST-- ReflectionFunction basic tests +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/025.phpt b/ext/reflection/tests/025.phpt index a5f604f56d..92002007b6 100644 --- a/ext/reflection/tests/025.phpt +++ b/ext/reflection/tests/025.phpt @@ -2,6 +2,9 @@ ReflectionFunction basic tests --SKIPIF-- <?php extension_loaded('reflection') or die('skip'); ?> +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt index 5feb560ae1..efa7e9a10a 100644 --- a/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt +++ b/ext/reflection/tests/ReflectionClass_getDocComment_001.phpt @@ -3,6 +3,9 @@ ReflectionClass::getDocComment() --CREDITS-- Robin Fernandes <robinf@php.net> Steve Seear <stevseea@php.net> +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php /** diff --git a/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt index 38c278d8a3..68d1d9d3a1 100644 --- a/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt +++ b/ext/reflection/tests/ReflectionFunction_getDocComment.001.phpt @@ -3,6 +3,9 @@ ReflectionFunction::getDocComment() --CREDITS-- Robin Fernandes <robinf@php.net> Steve Seear <stevseea@php.net> +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/ReflectionFunction_isGenerator_basic.phpt b/ext/reflection/tests/ReflectionFunction_isGenerator_basic.phpt new file mode 100644 index 0000000000..c4889b12bc --- /dev/null +++ b/ext/reflection/tests/ReflectionFunction_isGenerator_basic.phpt @@ -0,0 +1,52 @@ +--TEST-- +ReflectionFunction::isGenerator() +--FILE-- +<?php + +$closure1 = function() {return "this is a closure"; }; +$closure2 = function($param) { + yield $param; +}; + +$rf1 = new ReflectionFunction($closure1); +var_dump($rf1->isGenerator()); + +$rf2 = new ReflectionFunction($closure2); +var_dump($rf2->isGenerator()); + +function func1() { + return 'func1'; +} + +function func2() { + yield 'func2'; +} + +$rf1 = new ReflectionFunction('func1'); +var_dump($rf1->isGenerator()); + +$rf2 = new ReflectionFunction('func2'); +var_dump($rf2->isGenerator()); + + +class Foo { + public function f1() { + } + + public function f2() { + yield; + } +} + +$rc = new ReflectionClass('Foo'); +foreach($rc->getMethods() as $m) { + var_dump($m->isGenerator()); +} +?> +--EXPECTF-- +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(true) diff --git a/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt b/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt index c01f689cf4..b04fb6c9fc 100644 --- a/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getDocComment_basic.phpt @@ -1,5 +1,8 @@ --TEST-- ReflectionMethod::getDocComment() +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php /** diff --git a/ext/reflection/tests/ReflectionProperty_basic2.phpt b/ext/reflection/tests/ReflectionProperty_basic2.phpt index b7b21333d3..bc42d3f828 100644 --- a/ext/reflection/tests/ReflectionProperty_basic2.phpt +++ b/ext/reflection/tests/ReflectionProperty_basic2.phpt @@ -1,5 +1,8 @@ --TEST-- Test usage of ReflectionProperty methods isDefault(), getModifiers(), getDeclaringClass() and getDocComment(). +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt b/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt index 2c4815a35b..f94ee8ca4c 100644 --- a/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt +++ b/ext/reflection/tests/ReflectionProperty_getDocComment_basic.phpt @@ -1,5 +1,8 @@ --TEST-- Test ReflectionProperty::getDocComment() usage. +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php diff --git a/ext/reflection/tests/bug36308.phpt b/ext/reflection/tests/bug36308.phpt index 79aa5f8fa1..f923ee31ab 100644 --- a/ext/reflection/tests/bug36308.phpt +++ b/ext/reflection/tests/bug36308.phpt @@ -1,5 +1,8 @@ --TEST-- Reflection Bug #36308 (ReflectionProperty::getDocComment() does not reflect extended class commentary) +--INI-- +opcache.save_comments=1 +opcache.load_comments=1 --FILE-- <?php class Base { diff --git a/ext/reflection/tests/bug64007.phpt b/ext/reflection/tests/bug64007.phpt new file mode 100644 index 0000000000..32ec6a5610 --- /dev/null +++ b/ext/reflection/tests/bug64007.phpt @@ -0,0 +1,19 @@ +--TEST-- +Bug #64007 (There is an ability to create instance of Generator by hand) +--FILE-- +<?php +$reflection = new ReflectionClass('Generator'); +try { + $generator = $reflection->newInstanceWithoutConstructor(); + var_dump($generator); +} catch (Exception $e) { + var_dump($e->getMessage()); +} + +$generator = $reflection->newInstance(); +var_dump($generator); +?> +--EXPECTF-- +string(97) "Class Generator is an internal class that cannot be instantiated without invoking its constructor" + +Catchable fatal error: The "Generator" class is reserved for internal use and cannot be manually instantiated in %sbug64007.php on line %d |
