Only evaluate right hand side of ?? if left value is null#18
Open
TysonAndre wants to merge 5 commits intojaytaph:masterfrom
Open
Only evaluate right hand side of ?? if left value is null#18TysonAndre wants to merge 5 commits intojaytaph:masterfrom
?? if left value is null#18TysonAndre wants to merge 5 commits intojaytaph:masterfrom
Conversation
e23a782 to
a7e6f60
Compare
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)
$x = (function ($v1) {
return $v1[0];
})(\call_user_func(function ($v1) {
return isset($v1) ? array($v1) : null;
}, @$y) ?: array(2));
PHPRC is explained in https://secure.php.net/manual/en/configuration.file.php#configuration.file and used only to run test cases
a7e6f60 to
9ef6ec0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
It's possible to optimize the special cases.
reset()wasn't used because that would emit a warning in php7 ifnon-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),barmay throw)E.g. this converts
$x = $y ?? 2into the below expression(
?:is the only operator which evaluates the left hand side onceand conditionally evaluates the right hand side)
EDIT: Forgot that should be call_user_func on the outside