Skip to content

Commit eee5dcc

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Correctly handle extra named args for magic call in debug_backtrace_get_args()
2 parents c145c20 + b620d9d commit eee5dcc

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
GH-20435: ZEND_CALL_HAS_EXTRA_NAMED_PARAMS & magic methods in debug_backtrace_get_args()
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public static function __callStatic($name, $args) {
8+
echo (new Exception())->__toString(), "\n\n";
9+
}
10+
public function __call($name, $args) {
11+
echo (new Exception())->__toString(), "\n\n";
12+
}
13+
public function __invoke(...$args) {
14+
echo (new Exception())->__toString(), "\n";
15+
}
16+
}
17+
18+
$c = new C();
19+
$c->foo(bar: 'bar');
20+
C::foo(bar: 'bar');
21+
$c(bar: 'bar');
22+
23+
?>
24+
--EXPECTF--
25+
Exception in %s:%d
26+
Stack trace:
27+
#0 %s(%d): C->__call('foo', Array)
28+
#1 {main}
29+
30+
Exception in %s:%d
31+
Stack trace:
32+
#0 %s(%d): C::__callStatic('foo', Array)
33+
#1 {main}
34+
35+
Exception in %s:%d
36+
Stack trace:
37+
#0 %s(%d): C->__invoke(bar: 'bar')
38+
#1 {main}

Zend/zend_builtin_functions.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,12 +1795,14 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
17951795
ZVAL_EMPTY_ARRAY(arg_array);
17961796
}
17971797

1798-
if (ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
1798+
if ((ZEND_CALL_INFO(call) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS)
1799+
/* __call and __callStatic are non-variadic, potentially with
1800+
* HAS_EXTRA_NAMED_PARAMS set. Don't add extra args, as they're already
1801+
* contained in the 2nd param. */
1802+
&& (call->func->common.fn_flags & ZEND_ACC_VARIADIC)) {
17991803
zend_string *name;
18001804
zval *arg;
18011805

1802-
ZEND_ASSERT(call->func->common.fn_flags & ZEND_ACC_VARIADIC);
1803-
18041806
zend_attribute *attribute = zend_get_parameter_attribute_str(
18051807
call->func->common.attributes,
18061808
"sensitiveparameter",

0 commit comments

Comments
 (0)