diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2018-07-02 21:33:09 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2018-07-02 21:33:09 +0200 |
commit | 23ae6ca405f7133d8882e9957df69980362906ad (patch) | |
tree | 8d3a62bf5bb021d29a9ca41aad92b59245c75ac3 | |
parent | 826e403d2c3e284aff78a1ea982819e27be7d03e (diff) | |
download | php-git-23ae6ca405f7133d8882e9957df69980362906ad.tar.gz |
Fix check for invoking abstract method
-rw-r--r-- | ext/reflection/php_reflection.c | 28 | ||||
-rw-r--r-- | ext/reflection/tests/ReflectionMethod_invoke_on_abstract_method_after_setAccessible.phpt | 20 |
2 files changed, 33 insertions, 15 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 7a313813a9..03590d47e7 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3089,21 +3089,19 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic) GET_REFLECTION_OBJECT_PTR(mptr); - if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) - || (mptr->common.fn_flags & ZEND_ACC_ABSTRACT)) - && intern->ignore_visibility == 0) - { - if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Trying to invoke abstract method %s::%s()", - ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); - } else { - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Trying to invoke %s method %s::%s() from scope %s", - mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", - ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name), - ZSTR_VAL(Z_OBJCE_P(getThis())->name)); - } + if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Trying to invoke abstract method %s::%s()", + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name)); + return; + } + + if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) { + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Trying to invoke %s method %s::%s() from scope %s", + mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private", + ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name), + ZSTR_VAL(Z_OBJCE_P(getThis())->name)); return; } diff --git a/ext/reflection/tests/ReflectionMethod_invoke_on_abstract_method_after_setAccessible.phpt b/ext/reflection/tests/ReflectionMethod_invoke_on_abstract_method_after_setAccessible.phpt new file mode 100644 index 0000000000..c564d6c16b --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_invoke_on_abstract_method_after_setAccessible.phpt @@ -0,0 +1,20 @@ +--TEST-- +ReflectionMethod::invoke() on an abstract method should fail even after calling setAccessible(true) +--FILE-- +<?php + +abstract class Test { + abstract static function foo(); +} + +$rm = new ReflectionMethod('Test', 'foo'); +$rm->setAccessible(true); +try { + var_dump($rm->invoke(null)); +} catch (ReflectionException $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Trying to invoke abstract method Test::foo() |