]> granicus.if.org Git - php/commitdiff
Fix check for invoking abstract method
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 2 Jul 2018 19:33:09 +0000 (21:33 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 2 Jul 2018 19:33:09 +0000 (21:33 +0200)
ext/reflection/php_reflection.c
ext/reflection/tests/ReflectionMethod_invoke_on_abstract_method_after_setAccessible.phpt [new file with mode: 0644]

index 7a313813a9b2dab0bedcc701ba60548e7363a8ac..03590d47e7b3556baa28823e5fd0a2177eba14f1 100644 (file)
@@ -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 (file)
index 0000000..c564d6c
--- /dev/null
@@ -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()