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 | |
/** | |
* Scalar type declarations | |
*/ | |
//declare(strict_types=1); | |
function add(int $a, int $b) { | |
return $a + $b; | |
} |
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 | |
/** | |
* Return type declarations | |
*/ | |
//declare(strict_types=1); | |
function add(int $a, int $b): int{ | |
return (string)($a + $b); | |
} |
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 | |
/** | |
* Anonymous classes | |
*/ | |
$foo = new class { | |
public function foo() { | |
return "bar"; | |
} | |
}; |
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 | |
/** | |
* Closure::call() | |
*/ | |
class Foo | |
{ | |
private $foo = 'bar'; | |
} |
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 | |
/** | |
* Generator delegation | |
*/ | |
function gen() | |
{ | |
yield 1; | |
yield 2; | |
yield from gen2(); |
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 | |
/** | |
* Generator return expressions | |
*/ | |
$gen = (function() { | |
yield 1; | |
yield 2; | |
return 3; |
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 | |
/** | |
* Null coalesce operator | |
*/ | |
$array = ['foo'=>'bar']; | |
//PHP5 style | |
$message = isset($array['foo']) ? $array['foo'] : 'not set'; | |
echo $message.PHP_EOL; |
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 | |
/** | |
* Space ship operator | |
*/ | |
$array = [ | |
"1 <=> 1" => 1 <=> 1, | |
"1 <=> 2" =>1 <=> 2, | |
"2 <=> 1" => 2 <=> 1 | |
]; |
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 | |
/** | |
* Throwable interface | |
*/ | |
//Error as Throwable | |
try { | |
sqdf(); | |
} catch (Throwable $t) { |
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 | |
/** | |
* Dirname levels | |
*/ | |
echo dirname('/usr/local/bin').PHP_EOL; | |
echo dirname('/usr/local/bin',1).PHP_EOL; | |
echo dirname('/usr/local/bin',2).PHP_EOL; | |
echo dirname('/usr/local/bin',3).PHP_EOL; |