-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
Description
Description
There appears to be a bug in how the new pipe operator (|>) handles functions that return by reference. An expression using the pipe operator is not behaving identically to its equivalent standard function call, specifically when a reference is expected to be returned.
The expression "foo" |> get_ref(...) should, in theory, be functionally equivalent to $c = get_ref(...); $c("foo");. However, the two produce different results when the function is declared to return a reference.
This code correctly returns a reference to the static variable within get_ref without any errors ( https://3v4l.org/Ojaah ):
<?php
function &get_ref($_): string {
static $a = "f";
return $a;
}
function &get_ref2(): string {
$c = get_ref(...);
return $c("foo");
}
echo get_ref2();This version, which should be equivalent, incorrectly throws a notice ( https://3v4l.org/po5A6 ):
<?php
function &get_ref($_): string {
static $a = "f";
return $a;
}
function &get_ref2(): string {
return "foo" |> get_ref(...);
}
echo get_ref2();PHP Version
master
Operating System
N/A
iluuu1994