Hi everyone,
I think I've got this RFC into the expected state needed to announce it and
open discussion.
Trailing Boolean Operators
https://wiki.php.net/rfc/trailing_boolean_operators
If the link doesn't work, here's the raw url:
https://wiki.php.net/rfc/trailing_boolean_operators
The TL;DR is that we allow what I'm calling a 'dangling' ('optional' might
be the better word) trailing boolean operator. Mirroring trailing commas.
It's designed to be a purely additive QoL improvement to help reduce diffs.
I'm both excited and anxious to see what you all think of it.
Cheers,
Len
Hi everyone,
I think I've got this RFC into the expected state needed to announce it and
open discussion.Trailing Boolean Operators
https://wiki.php.net/rfc/trailing_boolean_operatorsIf the link doesn't work, here's the raw url:
https://wiki.php.net/rfc/trailing_boolean_operatorsThe TL;DR is that we allow what I'm calling a 'dangling' ('optional' might
be the better word) trailing boolean operator. Mirroring trailing commas.
It's designed to be a purely additive QoL improvement to help reduce diffs.I'm both excited and anxious to see what you all think of it.
Cheers,
Len
I do not see the lack of trailing (dangling) operators as inconsistent
with trailing commas. Commas aren't operators. Commas don't have
precedence. They don't affect program flow like boolean operators. I
think trailing boolean operators could be dangerous in very sneaky and
nuanced ways.
If you're concerned about diffs, put the boolean operators at the front:
if (
$order->isPaid()
&& $order->isShipped()
&& $order->isDelivered()
) {
$order->archive();
}
Now, you can add more to the if statement without having a cumbersome
diff. However, I would recommend reworking and simplifying the logic
instead. The more boolean operators you add, the higher the cognitive
complexity, and the more complicated your test cases are for this code path.
I would vote "no" on this RFC.
Cheers,
Ben
Trailing Boolean Operators
If the link doesn't work, here's the raw url:
https://wiki.php.net/rfc/trailing_boolean_operatorsThe TL;DR is that we allow what I'm calling a 'dangling' ('optional' might be the better word) trailing boolean operator. Mirroring trailing commas. It's designed to be a purely additive QoL improvement to help reduce diffs.
Hi Len,
I see that this is your first RFC, welcome, and well done on the RFC
draft. The RFC text is quite detailed, and clearly brings the idea
across. I appreciate that you explained your rationale, with simple
examples, and a well-defined scope. Greatly done.
As for the idea, however, I do not agree that this would be a
net-positive change. I wanted to echo what Ben said in his reply too.
Commas are fundamentally different from the operators like && and
||. One is a separator, the other is an operator. Trailing
separators do not add to the confusion, and the benefits you mention
in the RFC are meaningful improvements that do not add to visual
confusion.
&& and || are binary operators that require a right-hand operand.
Your RFC removes this requirement from the syntax, but I believe they
semantically still require a right-hand operand.
I'm also not aware of any other languages that allow trailing
operators. For PHP to add trailing commas, it had a strong argument in
favor because other languages like JavaScript, Python, and of course C
(among many other languages) supported it, and adding support for
trailing commas was a natural progression. Back then, even this was
argued quite a lot in the RFC discussions, and some proposals did not
pass the vote.
As Ben mentioned, the new-line, operator, and operand pattern solves
the diff issue. Besides, changing the order of an if block is a
significant change, and at least for me, not something I do often. For
changes like this, I would rather like it to have a more visually
stark diff.
Thanks,
Ayesh.
Hi
Am 2026-02-03 20:05, schrieb Len Woodward:
If the link doesn't work, here's the raw url:
https://wiki.php.net/rfc/trailing_boolean_operators
Thank you for the RFC. I second Ayesh's remark with how well-written the
RFC is. I have one minor housekeeping note: The Status in the RFC itself
is still set to “Draft”.
With regard to the “Trailing-Operator Style is Established” section, I'd
like to note that the latest edition of the “Code Style published by PHP
FIG” is the PER Coding Style 3.0 which requires the boolean operators at
the start of the line:
https://www.php-fig.org/per/coding-style/#51-if-elseif-else
Other than that, I share the concerns that have already been voiced in
this thread and thus won't repeat them.
Best regards
Tim Düsterhus
Hi
Am 2026-02-04 10:51, schrieb Tim Düsterhus:
If the link doesn't work, here's the raw url:
https://wiki.php.net/rfc/trailing_boolean_operatorsThank you for the RFC. I second Ayesh's remark with how well-written
the RFC is. I have one minor housekeeping note: The Status in the RFC
itself is still set to “Draft”.
Ah. One more thing: The voting widget is missing the “Abstain” option. I
just added it in myself, since it's a clear policy requirement. See:
https://github.com/php/policies/blob/main/feature-proposals.rst#required-majority
Best regards
Tim Düsterhus
Hi everyone,
I think I've got this RFC into the expected state needed to announce it
and open discussion.Trailing Boolean Operators
If the link doesn't work, here's the raw url:
https://wiki.php.net/rfc/trailing_boolean_operatorsThe TL;DR is that we allow what I'm calling a 'dangling' ('optional'
might be the better word) trailing boolean operator. Mirroring trailing
commas. It's designed to be a purely additive QoL improvement to help
reduce diffs.I'm both excited and anxious to see what you all think of it.
Cheers,
Len
Hi Len,
Thank you for the proposal, and congratulations on your first RFC!
However, I am not in favor of this specific change. Unlike commas, which
serve as separators, binary operators functionally demand a right-hand
operand. Allowing a trailing operator breaks this fundamental expectation
and introduces unnecessary ambiguity.
As a maintainer of a handwritten PHP parser (mago
https://github.com/carthage-software/mago), I can attest that supporting
this would be non-trivial. PHP's operator precedence/associativity is
already quite a mess (reference
https://github.com/carthage-software/mago/blob/main/crates/syntax/src/parser/internal/expression.rs#L738-L797),
and introducing trailing boolean operators adds parsing complexity without
providing proportional value to the language.
Cheers,
Seifeddine.