It's possible to optimize the special cases.
reset() wasn't used because that would emit a warning in php7 if
non-references were used.
Motivation: if the right hand size can throw,
then the transpiled code should only evaluate the right hand side
if the left hand side is null.
(E.g. foo($args) ?? bar($otherargs), bar may throw)
E.g. this converts $x = $y ?? 2 into the below expression
(?: is the only operator which evaluates the left hand side once
and conditionally evaluates the right hand side)
The empty array is falsey, the non-empty array is always truthy
It's possible to optimize the special cases.
reset()
wasn't used because that would emit a warning in php7 if non-references were used.Motivation: if the right hand size can throw, then the transpiled code should only evaluate the right hand side if the left hand side is
null
. (E.g.foo($args) ?? bar($otherargs)
,bar
may throw)E.g. this converts
$x = $y ?? 2
into the below expression (?:
is the only operator which evaluates the left hand side once and conditionally evaluates the right hand side)EDIT: Forgot that should be call_user_func on the outside