Skip to content

feat: add pipe assignment operator (|>=)#22633

Open
calebdw wants to merge 1 commit into
php:masterfrom
calebdw:calebdw/push-zkppokymsmqt
Open

feat: add pipe assignment operator (|>=)#22633
calebdw wants to merge 1 commit into
php:masterfrom
calebdw:calebdw/push-zkppokymsmqt

Conversation

@calebdw

@calebdw calebdw commented Jul 8, 2026

Copy link
Copy Markdown

Hello!

(aka, the weightlifter operator)

RFC: tbd (as soon as I get them wiki karma, username cdwhite3)

Thanks!

Adds the `|>=` compound assignment operator for the pipe operator,
allowing `$x |>= callable` to be used as shorthand for `$x = $x |> callable`.

Supports pipe chains on the RHS:
`$x |>= fn1(...) |> fn2(...) |> fn3(...)`
is equivalent to
`$x = $x |> fn1(...) |> fn2(...) |> fn3(...)`.

Implementation modeled after `??=` (ZEND_AST_ASSIGN_COALESCE), with a
dedicated AST node (ZEND_AST_ASSIGN_PIPE) and compiler function that
uses memoization to avoid double-evaluating complex LHS expressions.

Extracts shared callable dispatch logic into zend_pipe_build_fcall()
helper used by both `|>` and `|>=` compilation.

All variable target types supported: simple vars, array dims, object
properties, static properties.

@NickSdot NickSdot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got this review myself so it caught my eye.

$a |>= modify_ref(...);
var_dump($a);
} catch (\Error $e) {
echo $e->getMessage(), PHP_EOL;

@NickSdot NickSdot Jul 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo $e->getMessage(), PHP_EOL;
echo $e::class, ": ", $e->getMessage(), PHP_EOL;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP_EOL is actually correct.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP_EOL is actually correct.

Was hacking on a linter/fixer for this the other day. We don't have something like that yet, don't we?

try {
$x |>= (fn($v) => $v * 2) |> will_throw(...);
} catch (RuntimeException $e) {
echo "Caught: " . $e->getMessage() . "\n";

@NickSdot NickSdot Jul 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "Caught: " . $e->getMessage() . "\n";
echo $e::class, ": ", $e->getMessage(), PHP_EOL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants