Skip to content

Commit d94ef01

Browse files
TimWollacharmitro
authored andcommitted
Free the trampoline when deprecation on materializing __callStatic() of trait throws (php#17729)
Fixes php#17728
1 parent d6e4f6e commit d94ef01

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
@@ -1892,23 +1892,27 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_st
18921892
if (EXPECTED(fbc)) {
18931893
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
18941894
zend_abstract_method_call(fbc);
1895-
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
1896-
zend_string_release_ex(fbc->common.function_name, 0);
1897-
zend_free_trampoline(fbc);
1898-
}
1899-
fbc = NULL;
1895+
goto fail;
19001896
} else if (UNEXPECTED(fbc->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
19011897
zend_error(E_DEPRECATED,
19021898
"Calling static trait method %s::%s is deprecated, "
19031899
"it should only be called on a class using the trait",
19041900
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
19051901
if (EG(exception)) {
1906-
return NULL;
1902+
goto fail;
19071903
}
19081904
}
19091905
}
19101906

19111907
return fbc;
1908+
1909+
fail:
1910+
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
1911+
zend_string_release_ex(fbc->common.function_name, 0);
1912+
zend_free_trampoline(fbc);
1913+
}
1914+
1915+
return NULL;
19121916
}
19131917
/* }}} */
19141918

0 commit comments

Comments
 (0)