Skip to content

Commit 6009b8a

Browse files
Fix phpGH-19476: pipe operator fails to correctly handle returning by reference (phpGH-19478)
1 parent fb87b14 commit 6009b8a

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug GH-18850 (Repeated inclusion of file with __halt_compiler()
77
triggers "Constant already defined" warning). (ilutov)
8+
. Fixed bug GH-19476 (pipe operator fails to correctly handle returning
9+
by reference). (alexandre-daubois)
810

911
- ODBC:
1012
. Remove ODBCVER and assume ODBC 3.5. (Calvin Buckley)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Fix GH-19476: Pipe operator with function returning by reference
3+
--FILE--
4+
<?php
5+
6+
function &get_ref($_): string {
7+
static $a = "original";
8+
9+
$a .= " ".$_;
10+
11+
return $a;
12+
}
13+
14+
function &test_pipe_ref(): string {
15+
return "input" |> get_ref(...);
16+
}
17+
18+
$ref = &test_pipe_ref();
19+
echo "Before: " . $ref . "\n";
20+
$ref = "changed";
21+
echo "After: " . test_pipe_ref() . "\n";
22+
23+
?>
24+
--EXPECT--
25+
Before: original input
26+
After: changed input

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2726,7 +2726,8 @@ static inline bool zend_is_call(zend_ast *ast) /* {{{ */
27262726
return ast->kind == ZEND_AST_CALL
27272727
|| ast->kind == ZEND_AST_METHOD_CALL
27282728
|| ast->kind == ZEND_AST_NULLSAFE_METHOD_CALL
2729-
|| ast->kind == ZEND_AST_STATIC_CALL;
2729+
|| ast->kind == ZEND_AST_STATIC_CALL
2730+
|| ast->kind == ZEND_AST_PIPE;
27302731
}
27312732
/* }}} */
27322733

0 commit comments

Comments
 (0)