Модуль 1. Нові можливості PHP 8.4 та строга типізація
⚡ Нагорода: +100 XP
Строга типізація, класи та Property Hooks у PHP 8.4
Що нового у PHP 8.4?
PHP 8.4 представив революційну можливість — Property Hooks (гачки властивостей), а також подальший розвиток строгої типізації (declare(strict_types=1);).
<?php
declare(strict_types=1);
class Student
{
public string $name {
set(string $value) {
$this->name = trim($value);
}
}
public function __construct(
string $name,
public int $xp = 0
) {
$this->name = $name;
}
}
🎯 Практичне завдання:
Напишіть PHP-клас Course із конструктором (Constructor Property Promotion), який приймає public string $title та public int $lessonsCount, і метод getSummary(): string.