Skip to content

Commit 6024122

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Free the trampoline when deprecation on materializing `__callStatic()` of trait throws (php#17729)
2 parents 7638653 + 0410369 commit 6024122

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Zend/tests/gh_17728.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GH-17728: Assertion failure when calling static method of trait with `__callStatic()` with throwing error handler
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
7+
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
8+
});
9+
10+
trait Foo {
11+
public static function __callStatic($method, $args) {
12+
var_dump($method);
13+
}
14+
}
15+
16+
try {
17+
Foo::bar();
18+
} catch (ErrorException $e) {
19+
echo $e->getMessage(), PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
Calling static trait method Foo::bar is deprecated, it should only be called on a class using the trait

Zend/zend_object_handlers.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,23 +1898,27 @@ 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-
}
1905-
fbc = NULL;
1901+
goto fail;
19061902
} else if (UNEXPECTED(fbc->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
19071903
zend_error(E_DEPRECATED,
19081904
"Calling static trait method %s::%s is deprecated, "
19091905
"it should only be called on a class using the trait",
19101906
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
19111907
if (EG(exception)) {
1912-
return NULL;
1908+
goto fail;
19131909
}
19141910
}
19151911
}
19161912

19171913
return fbc;
1914+
1915+
fail:
1916+
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
1917+
zend_string_release_ex(fbc->common.function_name, 0);
1918+
zend_free_trampoline(fbc);
1919+
}
1920+
1921+
return NULL;
19181922
}
19191923
/* }}} */
19201924

0 commit comments

Comments
 (0)