Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Zend/tests/gh_17728.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
GH-17728: Assertion failure when calling static method of trait with `__callStatic()` with throwing error handler
--FILE--
<?php

set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
});

trait Foo {
public static function __callStatic($method, $args) {
var_dump($method);
}
}

try {
Foo::bar();
} catch (ErrorException $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
Calling static trait method Foo::bar is deprecated, it should only be called on a class using the trait
16 changes: 10 additions & 6 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1541,23 +1541,27 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_st
if (EXPECTED(fbc)) {
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
zend_abstract_method_call(fbc);
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
zend_string_release_ex(fbc->common.function_name, 0);
zend_free_trampoline(fbc);
}
fbc = NULL;
goto fail;
} else if (UNEXPECTED(fbc->common.scope->ce_flags & ZEND_ACC_TRAIT)) {
zend_error(E_DEPRECATED,
"Calling static trait method %s::%s is deprecated, "
"it should only be called on a class using the trait",
ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name));
if (EG(exception)) {
return NULL;
goto fail;
}
}
}

return fbc;

fail:
if (UNEXPECTED(fbc->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE)) {
zend_string_release_ex(fbc->common.function_name, 0);
zend_free_trampoline(fbc);
}

return NULL;
}
/* }}} */

Expand Down
Loading