Created
November 26, 2013 19:35
-
-
Save philsturgeon/7664724 to your computer and use it in GitHub Desktop.
Proposed short logical assignment operator
This file contains 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
<?php | |
$foo = null; | |
// If's - verbose and uneccassry | |
if (! $foo) { | |
$foo = 'default'; | |
} | |
// Short Ternary syntax | |
$foo = $foo ?: 'default'; | |
// Long Operator syntax (see, this is nothing new or alien to PHP, but still writing $foo twice) | |
$foo || $foo = 'default'; | |
// Proposed Short Operator syntax (Ruby Style - Consistency issues raised, as all | |
// PHP assignment operators are formed as <op>= and equate to $x = $x <op> $y, while this is $x = $x <op> $y) | |
$foo ||= "default"; | |
// Proposed Short Operator syntax (Avoids the issue by moving the operator to avoid confusion with other <op>=) | |
$foo =|| "default"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment