PHP 8.4 release bo’ldi.Yangiliklar:
-
Property hooks. C# da bor edi bu narsa, getter/setter larni, propertyni o’ziga yozib ketish:
php < 8.4
class Test
{
public function __construct(
private string $phpVersion,
) {}
public function getPhpVersion()
{
return $this->phpVersion;
}
public function setPhpVersion(string $version)
{
$this->phpVersion = $version;
}
}
php 8.4
class Test
{
public string $phpVersion
{
get => $this->phpVersion;
set (string $version) {
$this->version = $version;
}
}
}
- As
ymmetric Visibility. Swiftda bor edi bu feature. Bu imkoniyat sizga o’zgaruvchini kim o’qiy olishi va kim o’zgartira olishini boshqarish imkonini osonlashtirib beradi.
php < 8.4
class Test
{
public string $version = '8.3';
}
$test = new Test();
var_dump($test->version); // string(3) "8.3"
$test->version = 'PHP 8.4'; // No error
php 8.4
class Test
{
public private(set) string $version = '8.4';
}
$test = new Test();
var_dump($test->version); // string(3) "8.4"
$test->version = 'PHP 8.3'; // Visibility error
- De
precated attribute. Eskirgan property, method yoki classlarga shu attribute ishlatilinsa, bu uni eskirganini bildiradi va dasturchiga ogohlantirish beradi.
- class obektini yaratib qavssiz methodni chaqirish: new MyClass()->method(). Javada ko’rgandim bu narsani juda qulaylik beradi:
php < 8.4
var_dump((new Test())->getPhpVersion());
php 8.4
var_dump(new Test()->getVersion());
- Yangi array_* funksiyalar: array_find(), array_find_key(), array_any(), va array_all()
Qolgan yangiliklarni shu yerda o’qishingiz mumkin:
https://www.php.net/releases/8.4/en.php@fnematov_blog