Skip to content

Commit 23ae6ca

Browse files
committed
Fix check for invoking abstract method
1 parent 826e403 commit 23ae6ca

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

ext/reflection/php_reflection.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,21 +3089,19 @@ static void reflection_method_invoke(INTERNAL_FUNCTION_PARAMETERS, int variadic)
30893089

30903090
GET_REFLECTION_OBJECT_PTR(mptr);
30913091

3092-
if ((!(mptr->common.fn_flags & ZEND_ACC_PUBLIC)
3093-
|| (mptr->common.fn_flags & ZEND_ACC_ABSTRACT))
3094-
&& intern->ignore_visibility == 0)
3095-
{
3096-
if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
3097-
zend_throw_exception_ex(reflection_exception_ptr, 0,
3098-
"Trying to invoke abstract method %s::%s()",
3099-
ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
3100-
} else {
3101-
zend_throw_exception_ex(reflection_exception_ptr, 0,
3102-
"Trying to invoke %s method %s::%s() from scope %s",
3103-
mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
3104-
ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name),
3105-
ZSTR_VAL(Z_OBJCE_P(getThis())->name));
3106-
}
3092+
if (mptr->common.fn_flags & ZEND_ACC_ABSTRACT) {
3093+
zend_throw_exception_ex(reflection_exception_ptr, 0,
3094+
"Trying to invoke abstract method %s::%s()",
3095+
ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name));
3096+
return;
3097+
}
3098+
3099+
if (!(mptr->common.fn_flags & ZEND_ACC_PUBLIC) && intern->ignore_visibility == 0) {
3100+
zend_throw_exception_ex(reflection_exception_ptr, 0,
3101+
"Trying to invoke %s method %s::%s() from scope %s",
3102+
mptr->common.fn_flags & ZEND_ACC_PROTECTED ? "protected" : "private",
3103+
ZSTR_VAL(mptr->common.scope->name), ZSTR_VAL(mptr->common.function_name),
3104+
ZSTR_VAL(Z_OBJCE_P(getThis())->name));
31073105
return;
31083106
}
31093107

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
ReflectionMethod::invoke() on an abstract method should fail even after calling setAccessible(true)
3+
--FILE--
4+
<?php
5+
6+
abstract class Test {
7+
abstract static function foo();
8+
}
9+
10+
$rm = new ReflectionMethod('Test', 'foo');
11+
$rm->setAccessible(true);
12+
try {
13+
var_dump($rm->invoke(null));
14+
} catch (ReflectionException $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
18+
?>
19+
--EXPECT--
20+
Trying to invoke abstract method Test::foo()

0 commit comments

Comments
 (0)