Last active
March 6, 2019 15:48
-
-
Save davidsword/913bfb60b00642c74a1212d6bc360046 to your computer and use it in GitHub Desktop.
PHP7 - New Feature! Null coalescing operator. Quickly do isset check and defines.
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
<?php | |
/** | |
* The new null coalescing operator! π | |
* @see http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op | |
*/ | |
$username = $_GET['user'] ?? 'nobody'; | |
// The old way. π | |
$username = isset( $_GET['user'] ) ? $_GET['user'] : 'nobody'; | |
// The _really_ old way. π | |
if ( isset( $_GET['user'] ) ) { | |
$username = $_GET['user']; | |
} else { | |
$username = 'nobody'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment