Skip to content

Commit 00d4390

Browse files
authored
Free the trampoline when deprecation on materializing __callStatic() of trait throws (#17729)
Fixes #17728
1 parent 0607b66 commit 00d4390

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

Zend/tests/gh_17728.phpt

+24
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

+10-6
Original file line numberDiff line numberDiff line change
@@ -1541,23 +1541,27 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_st
15411541
if (EXPECTED(fbc)) {
15421542
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
15431543
zend_abstract_method_call(fbc);
1544-
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
1545-
zend_string_release_ex(fbc->common.function_name, 0);
1546-
zend_free_trampoline(fbc);
1547-
}
1548-
fbc = NULL;
1544+
goto fail;
15491545
} else if (UNEXPECTED(fbc->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
15501546
zend_error(E_DEPRECATED,
15511547
"Calling static trait method %s::%s is deprecated, "
15521548
"it should only be called on a class using the trait",
15531549
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
15541550
if (EG(exception)) {
1555-
return NULL;
1551+
goto fail;
15561552
}
15571553
}
15581554
}
15591555

15601556
return fbc;
1557+
1558+
fail:
1559+
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
1560+
zend_string_release_ex(fbc->common.function_name, 0);
1561+
zend_free_trampoline(fbc);
1562+
}
1563+
1564+
return NULL;
15611565
}
15621566
/* }}} */
15631567

0 commit comments

Comments
 (0)