Skip to content

Commit 35be6d0

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Disallow calls to abstract `__call()` / `__callStatic()` (php#17719)
2 parents 459fc9d + e13d25e commit 35be6d0

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Zend/tests/gh_17718_001.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-17718: Disallow calling abstract `__callStatic()` trampoline on an interface
3+
--FILE--
4+
<?php
5+
6+
interface Foo {
7+
public static function __callStatic($method, $args);
8+
}
9+
10+
Foo::bar();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Error: Cannot call abstract method Foo::bar() in %s:%d
15+
Stack trace:
16+
#0 {main}
17+
thrown in %s on line %d

Zend/tests/gh_17718_002.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-17718: Disallow calling abstract `__callStatic()` trampoline on an abstract class
3+
--FILE--
4+
<?php
5+
6+
abstract class Foo {
7+
abstract public static function __callStatic($method, $args);
8+
}
9+
10+
Foo::bar();
11+
12+
?>
13+
--EXPECTF--
14+
Fatal error: Uncaught Error: Cannot call abstract method Foo::bar() in %s:%d
15+
Stack trace:
16+
#0 {main}
17+
thrown in %s on line %d

Zend/zend_object_handlers.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
16171617
func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE
16181618
| ZEND_ACC_PUBLIC
16191619
| ZEND_ACC_VARIADIC
1620-
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_DEPRECATED));
1620+
| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED));
16211621
if (fbc->common.attributes) {
16221622
func->attributes = fbc->common.attributes;
16231623
GC_TRY_ADDREF(func->attributes);
@@ -1898,6 +1898,10 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_st
18981898
if (EXPECTED(fbc)) {
18991899
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
19001900
zend_abstract_method_call(fbc);
1901+
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
1902+
zend_string_release_ex(fbc->common.function_name, 0);
1903+
zend_free_trampoline(fbc);
1904+
}
19011905
fbc = NULL;
19021906
} else if (UNEXPECTED(fbc->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
19031907
zend_error(E_DEPRECATED,

0 commit comments

Comments
 (0)