com php-src: Fix check for invoking abstract method: ext/reflection/php_reflection.c ext/reflection/tests/Refl
ectionMethod_invoke_on_abstract_method_after_setAcc essible.phpt
| From: | Nikita Popov | Date: | Mon, 02 Jul 2018 19:33:09 +0000 |
| Subject: | com php-src: Fix check for invoking abstract method: ext/reflection/php_reflection.c ext/reflection/tests/Refl ectionMethod_invoke_on_abstract_method_after_setAcc essible.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-102371@lists.php.net to get a copy of this message | ||
Commit: 23ae6ca405f7133d8882e9957df69980362906ad
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 2 Jul 2018 21:33:09 +0200
Parents: 826e403d2c3e284aff78a1ea982819e27be7d03e
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=23ae6ca405f7133d8882e9957df69980362906ad
Log:
Fix check for invoking abstract method
Changed paths:
M ext/reflection/php_reflection.c
A ext/reflection/tests/ReflectionMethod_invoke_on_abstract_method_after_setAccessible.phpt
Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 7a31381..03590d4 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 0000000..c564d6c
--- /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()