function add(int $a, int $b): int {
return $a + $b;
}
function divide(float $a, float $b): float {
return $a / $b;
}
$name = $_GET['name'] ?? 'Unknown';
$result = $a <=> $b;
$object = new class {
public function hello() {
echo "Hello!";
}
};
$object->hello();
define('FRUITS', [
'apple',
'banana',
'orange'
]);
try {
// Some code that may throw an exception
} catch (Exception $e) {
// Handle the exception
}
这些只是PHP7中的一些特性,还有其他一些特性如生成器、匿名函数的改进、多异常捕获等也值得学习和掌握。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站