What’s new in PHP 8.2
- Release: https://www.php.net/releases/8.2/ru.php
- Wiki: PHP 8.2
- 8.1>8.2 Migration: https://www.php.net/manual/ru/migration82.new-features.php
- github: PHP 8.2 changelog
- habr: https://habr.com/ru/company/hexlet/blog/705194/
null, false, true ― standalone types
Wiki: https://wiki.php.net/rfc/null-false-standalone-types
Wiki: https://wiki.php.net/rfc/true-type
class Falsy
{
public function alwaysFalse(): false { /* ... */ *}
public function alwaysTrue(): true { /* ... */ *}
public function alwaysNull(): null { /* ... */ *}
}
Dynamic properties of a class are deprecated
Doc: https://www.php.net/manual/ru/migration82.deprecated.php#migration82.deprecated.core.dynamic-properties
Wiki: https://wiki.php.net/rfc/deprecate_dynamic_properties
To help avoid errors and typos, it is no longer recommended to define dynamic properties.
Use the attribute #[\AllowDynamicProperties] on the class when you need to allow dynamic properties.
In stdClass instances dynamic properties are still allowed.
class User {
public $name;
}
$user = new User();
$user->last_name = 'Doe'; // Deprecated notice
$user = new stdClass();
$user->last_name = 'Doe'; // Allowed
This change does not affect the use of magic methods __get()/__set().
Constants in traits
Doc: https://www.php.net/manual/ru/migration82.new-features.php#migration82.new-features.core.constant-in-traits
Wiki: https://wiki.php.net/rfc/constants_in_traits
You cannot access a constant via the trait name, but you can through the class that uses this trait:
trait Foo {
public const CONSTANT = 1;
}
class Bar {
use Foo;
}
var_dump( Bar::CONSTANT ); // 1
var_dump( Foo::CONSTANT ); // Error—