Skip to content

Instantly share code, notes, and snippets.

@up1
Last active December 4, 2015 03:23
Show Gist options
  • Save up1/cbc143a8b8b25581b2ff to your computer and use it in GitHub Desktop.
Save up1/cbc143a8b8b25581b2ff to your computer and use it in GitHub Desktop.
Hello PHP 7
<?php
define('ALLOWED_IMAGE_EXTENSIONS', ['jpg', 'jpeg', 'gif', 'png']);
var_dump(ALLOWED_IMAGE_EXTENSIONS);
?>
<?php
// Pre PHP 7 code
$username = isset($_GET['username']) ? $_GET['username'] : 'DEFAULT';
// PHP 7
$username = $_GET['username'] ?? 'DEFAULT';
echo $username;
?>
<?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
<?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