[php-src] master: Fix GH-19476: pipe operator fails to correctly handle returning by reference (GH-19478)
Author: Alexandre Daubois (alexandre-daubois)
Committer: GitHub (web-flow)
Pusher: iluuu1994
Date: 2025-08-14T16:34:21+02:00
Commit: https://github.com/php/php-src/commit/6009b8a100973f2296a8018362573676f5d4461b
Raw diff: https://github.com/php/php-src/commit/6009b8a100973f2296a8018362573676f5d4461b.diff
Fix GH-19476: pipe operator fails to correctly handle returning by reference (GH-19478)
Changed paths:
A Zend/tests/pipe_operator_reference_context.phpt
M NEWS
M Zend/zend_compile.c
Diff:
diff --git a/NEWS b/NEWS
index 77c1e32ff3a8..0180f5b3478a 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP NEWS
- Core:
. Fixed bug GH-18850 (Repeated inclusion of file with __halt_compiler()
triggers "Constant already defined" warning). (ilutov)
+ . Fixed bug GH-19476 (pipe operator fails to correctly handle returning
+ by reference). (alexandre-daubois)
- ODBC:
. Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley)
diff --git a/Zend/tests/pipe_operator_reference_context.phpt
b/Zend/tests/pipe_operator_reference_context.phpt
new file mode 100644
index 000000000000..7d7572e2b2e5
--- /dev/null
+++ b/Zend/tests/pipe_operator_reference_context.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Fix GH-19476: Pipe operator with function returning by reference
+--FILE--
+<?php
+
+function &get_ref($_): string {
+ static $a = "original";
+
+ $a .= " ".$_;
+
+ return $a;
+}
+
+function &test_pipe_ref(): string {
+ return "input" |> get_ref(...);
+}
+
+$ref = &test_pipe_ref();
+echo "Before: " . $ref . "\n";
+$ref = "changed";
+echo "After: " . test_pipe_ref() . "\n";
+
+?>
+--EXPECT--
+Before: original input
+After: changed input
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index db611be49ab4..aba735124a0a 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2726,7 +2726,8 @@ static inline bool zend_is_call(zend_ast *ast) /* {{{ */
return ast->kind == ZEND_AST_CALL
|| ast->kind == ZEND_AST_METHOD_CALL
|| ast->kind == ZEND_AST_NULLSAFE_METHOD_CALL
- || ast->kind == ZEND_AST_STATIC_CALL;
+ || ast->kind == ZEND_AST_STATIC_CALL
+ || ast->kind == ZEND_AST_PIPE;
}
/* }}} */
Thread (1 message)
- Alexandre Daubois via GitHub