[php-src] PR #25445: Fix GH-25404: Unwrap by-reference returns forwarded by SPL methods
| From: | Truta446 | Date: | Fri, 13 Nov 2026 13:47:11 +0000 |
| Subject: | [php-src] PR #25445: Fix GH-25404: Unwrap by-reference returns forwarded by SPL methods | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40626@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25445
Author: Truta446
Fixes GH-25404
RecursiveIteratorIterator::callHasChildren(), callGetChildren() and
RecursiveFilterIterator::hasChildren() pass their return_value straight to
the user method. If that method returns by reference, the reference ends up in the return value of a
function that is not by-ref, and the assertion after the call in the VM fails.
The fix unwraps the reference after the call, the same way
CallbackFilterIterator::accept() and zend_test's
zend_call_method_if_exists() already do. zend_return_unwrap_ref()
isn't the right fit here: these methods never return by reference, so the reference has to go
regardless of how they are called. zend_call_method() in zend_test gets the same fix,
since it's the fourth case in the issue.
I also went through the other places that pass return_value to a user call
(array_reduce(), ReflectionProperty::getValue() with a by-ref get hook,
CallbackFilterIterator, call_user_func()), and they are fine. One thing I
noticed while doing that: PDOStatement::fetchAll(PDO::FETCH_FUNC, ...) with a by-ref
function puts the reference into the result array, so writing to the array changes the referenced
variable. That is the same on 8.4 and 8.5 and doesn't trip any assertion, so I left it out of
this PR.
Tested on PHP-8.6 and master (debug + ASan, also with opcache/tracing JIT):
ext/spl/tests and ext/zend_test/tests all pass, and both new tests fail
without the change.