Skip to content

Fix GH-16908: _ZendTestMagicCallForward does not handle references well #16919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 5 additions & 2 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,12 @@ static ZEND_METHOD(_ZendTestMagicCallForward, __call)

ZEND_IGNORE_VALUE(arguments);

zval func;
zval func, rv;
ZVAL_STR(&func, name);
call_user_function(NULL, NULL, &func, return_value, 0, NULL);
call_user_function(NULL, NULL, &func, &rv, 0, NULL);

ZVAL_COPY_DEREF(return_value, &rv);
zval_ptr_dtor(&rv);
}

PHP_INI_BEGIN()
Expand Down
20 changes: 20 additions & 0 deletions ext/zend_test/tests/gh16908.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-16908 (_ZendTestMagicCallForward does not handle references well)
--EXTENSIONS--
zend_test
--FILE--
<?php
$cls = new _ZendTestMagicCallForward();
function &foo() {
}
$cls->foo()->x ??= 42;
?>
--EXPECTF--
Notice: Only variable references should be returned by reference in %s on line %d

Notice: Only variable references should be returned by reference in %s on line %d

Fatal error: Uncaught Error: Attempt to assign property "x" on null in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
Loading