Alpha testing of PHP 8.2 has begun

The first alpha release of the new branch of the PHP 8.2 programming language is presented. The release is scheduled for November 24th. The main innovations already available for testing or planned for implementation in PHP 8.2:

  • Separate types "false" and "null" have been added, which can be used, for example, to return a sign of completion with an error or an empty value by a function. Previously, "false" and "null" could only be used in conjunction with other types (for example, "string|false"), but now they can be used separately: function alwaysFalse(): false { return false; }
  • Added the ability to mark a class as read-only. Properties in such classes can be set only once, after which they will not be available for change. Previously, individual class properties could be marked read-only, but now you can turn on this mode for all class properties at once. Specifying the "readonly" flag at the class level also blocks the dynamic addition of properties to the class. readonly class Post { public function __construct( public string $title, public Author $author, ) {} } $post = new Post(/* … */); $post->unknown = 'wrong'; // Error: Cannot create dynamic property Post::$unknown
  • Deprecated the ability to dynamically create properties in a class (like "post->unknown" in the example above). In PHP 9.0, accessing properties not originally defined in the class will result in an error (ErrorException). Classes that provide __get and __set methods for creating properties, or dynamic properties in stdClass will continue to work as is, and only implicit handling of non-existent properties will no longer be supported in order to protect the developer from hidden bugs. To keep the old code working, the "#[AllowDynamicProperties]" attribute is proposed, allowing the use of dynamic properties.
  • Provided the ability to filter sensitive settings in the stack trace output at the time of an error. Cutting out certain information may be required when information about errors that occur is automatically sent to third-party services that track problems and inform developers about them. For example, you can exclude parameters from the trace that include usernames, passwords, and environment variables. function test( $foo, #[\SensitiveParameter] $password, $baz ) { throw new Exception('Error'); } test('foo', 'password', 'baz'); Fatal error: Uncaught Exception: Error in test.php:8 Stack trace: #0 test.php(11): test('foo', Object(SensitiveParameterValue), 'baz') #1 {main} thrown in test.php online 8
  • The ability to substitute variable values ​​into strings using "${var}" and ${(var)}" expressions has been deprecated. Support for commonly used "{$var}" and "$var" substitutions has been retained. For example: "Hello {$world}"; OK "Hello $world"; OK "Hello ${world}"; Deprecated: Using ${} in strings is deprecated
  • Partially supported callables that can be called via "call_user_func($callable)" have been deprecated, but do not support calling in the form "$callable()": "self::method" "parent::method" "static ::method" ["self", "method"] ["parent", "method"] ["static", "method"] ["Foo", "Bar::method"] [new Foo, "Bar: :method"]
  • Implemented locale-independent case conversion. Functions like strtolower() and strtoupper() now always convert the case of characters in the ASCII range, as when setting the locale to "C".

Source: opennet.ru

Add a comment