function sum(int $a, int $b): int {
return $a + $b;
}
declare(strict_types=1)
) и нестрогого типизирования$username = $_GET['user'] ?? 'anonymous';
usort($array, fn($a, $b) => $a <=> $b);
function gen() {
yield 1;
return "done";
}
assert($age > 18, "User must be adult");
; php.ini
opcache.jit_buffer_size=100M
opcache.jit=tracing
#[Route("/api/posts", methods: ["GET"])]
class PostController {}
class User {
public function __construct(
public string $name,
protected int $age
) {}
}
$result = match($statusCode) {
200, 201 => 'success',
404 => 'not found',
default => 'unknown'
};
$country = $user?->getAddress()?->country;
array_fill(start_index: 0, num: 5, value: 50);
class BlogPost {
public readonly string $title;
}
enum Status: string {
case DRAFT = 'draft';
case PUBLISHED = 'published';
}
$data = ["name" => "John", "age" => 25];
["name" => $username, "age" => $userAge] = $data;
PHP 7 принес революционную производительность и базовую типизацию, тогда как PHP 8 сосредоточился на выразительности кода, безопасности типов и экосистемных улучшениях. Переход на PHP 8.x особенно важен для современных веб-приложений.