Last active
December 4, 2015 03:23
-
-
Save up1/cbc143a8b8b25581b2ff to your computer and use it in GitHub Desktop.
Hello PHP 7
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 | |
define('ALLOWED_IMAGE_EXTENSIONS', ['jpg', 'jpeg', 'gif', 'png']); | |
var_dump(ALLOWED_IMAGE_EXTENSIONS); | |
?> |
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 | |
// Pre PHP 7 code | |
$username = isset($_GET['username']) ? $_GET['username'] : 'DEFAULT'; | |
// PHP 7 | |
$username = $_GET['username'] ?? 'DEFAULT'; | |
echo $username; | |
?> |
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 | |
declare(strict_types=1); | |
function sumOfInts(int ...$ints){ | |
return array_sum($ints); | |
} | |
sumOfInts(2, '3', 4.1); | |
?> | |
//Output | |
PHP Fatal error: Uncaught TypeError: Argument 2 passed to sumOfInts() must be of the type integer |
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 | |
var_dump('PHP 7' <=> 'PHP 5'); // int(1) | |
var_dump(123 <=> 456); // int(-1) | |
var_dump(['a', 'b'] <=> ['a', 'b']); // int(0) | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment