Alpha testing of PHP 8.1 has begun.

The first alpha release of the new branch of the PHP programming language 8.1 has been introduced. The release is scheduled for November 25. Key innovations already available for testing or planned for implementation in PHP 8.1 include:

  • Support for enumerations has been added, allowing the following constructs: enum Status { case Pending; case Active; case Archived; } class Post { public function __construct( private Status $status = Status::Pending; ) {} public function setStatus(Status $status): void { // … } } $post->setStatus(Status::Active);
  • Support for lightweight threads, called fibers, has been added, enabling low-level concurrency management. Fiber support is planned to be integrated into the Amphp and ReactPHP frameworks. $fiber = new Fiber(function (): void { $valueAfterResuming = Fiber::suspend('after suspending'); // … }); $valueAfterSuspending = $fiber->start(); $fiber->resume('after resuming');
  • The implementation of the object code cache (opcache) has been improved, now allowing caching of class inheritance information. This optimization has increased the performance of some applications by 5-8%.
  • The unpacking operator within arrays '…$var', allowing for the substitution of existing arrays when defining a new array, has been expanded to support string keys (previously only numerical identifiers were supported). For example, you can now use in code: $array1 = ['a' => 1]; $array2 = ['b' => 2]; $array = ['a' => 0, …$array1, …$array2]; var_dump($array); // ['a' => 1, 'b' => 2]
  • A new type 'never' has been introduced, which can be used to inform static analyzers that a function stops program execution, for instance, by throwing an exception or calling the exit function. function dd(mixed $input): never { exit; }
  • A new function array_is_list has been proposed, allowing you to determine if the keys in an array are arranged in increasing numerical order starting from 0: $list = ['a', 'b', 'c']; array_is_list($list); // true $notAList = [1 => 'a', 2 => 'b', 3 => 'c']; array_is_list($notAList); // false $alsoNotAList = ['a' => 'a', 'b' => 'b', 'c' => 'c']; array_is_list($alsoNotAList); // false
  • The possibility of overriding constants in a class during inheritance has been proposed. To prevent overriding constants of the parent class, the keyword "final" can be used. class Foo { public const X = "foo"; final public const Z = "foo"; } class Bar extends Foo { public const X = "bar"; }
  • Functions fsync and fdatasync have been introduced for forcing changes from disk cache to be saved. $file = fopen("sample.txt", "w"); fwrite($file, "Some content"); if (fsync($file)) { echo "File has been successfully persisted to disk."; } fclose($file);
  • The ability to use the prefixes "0o" and "0O" for octal numbers has been added, in addition to the previously used prefix "0". 016 === 0o16; // true 016 === 0O16; // true
  • The selective limitation of the use of $GLOBALS has been proposed, which will lead to backward compatibility issues but will significantly speed up array operations. For example, the possibility of prohibiting writing to $GLOBALS and passing $GLOBALS by reference is being considered. An analysis of 2000 packages showed that only 23 of them would be affected by this change. If the proposal is approved, support for such expressions as will be discontinued in 8.1: $GLOBALS = []; $GLOBALS += []; $GLOBALS =& $x; $x =& $GLOBALS; unset($GLOBALS); by_ref($GLOBALS);
  • Work has continued to transition functions from resource usage to object manipulation. The functions finfo_* and imap_* have been transitioned to objects.
  • Passing null values as arguments to internal functions marked as non-nullable has been declared deprecated. In PHP 8.1, using constructs like str_contains("string", null) will trigger a warning, and in PHP 9, it will cause an error.
  • Support for the MurmurHash3 and xxHash hashing algorithms has been added.

Source: opennet.ru

Buy reliable website hosting with DDoS protection, VPS VDS servers 🔥 Buy reliable website hosting with DDoS protection, VPS VDS servers | ProHoster