Skip to content

Commit d9fada4

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix GH-16908: _ZendTestMagicCallForward does not handle references well
2 parents 4ceae71 + 99f5653 commit d9fada4

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

ext/zend_test/test.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,12 @@ static ZEND_METHOD(_ZendTestMagicCallForward, __call)
10621062

10631063
ZEND_IGNORE_VALUE(arguments);
10641064

1065-
zval func;
1065+
zval func, rv;
10661066
ZVAL_STR(&func, name);
1067-
call_user_function(NULL, NULL, &func, return_value, 0, NULL);
1067+
call_user_function(NULL, NULL, &func, &rv, 0, NULL);
1068+
1069+
ZVAL_COPY_DEREF(return_value, &rv);
1070+
zval_ptr_dtor(&rv);
10681071
}
10691072

10701073
PHP_INI_BEGIN()

ext/zend_test/tests/gh16908.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-16908 (_ZendTestMagicCallForward does not handle references well)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
$cls = new _ZendTestMagicCallForward();
8+
function &foo() {
9+
}
10+
$cls->foo()->x ??= 42;
11+
?>
12+
--EXPECTF--
13+
Notice: Only variable references should be returned by reference in %s on line %d
14+
15+
Notice: Only variable references should be returned by reference in %s on line %d
16+
17+
Fatal error: Uncaught Error: Attempt to assign property "x" on null in %s:%d
18+
Stack trace:
19+
#0 {main}
20+
thrown in %s on line %d

0 commit comments

Comments
 (0)