PHP 8 beta testing has begun

Submitted by the first beta release of a new branch of the PHP 8 programming language. The release is scheduled for November 26th. Corrective releases of PHP 7.4.9, 7.3.21 and
7.2.33, which eliminated the accumulated errors and vulnerabilities.

All innovations PHP 8:

  • Π’ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ JIT compiler, the use of which will improve performance.
  • Support named function arguments that allow you to pass values ​​to the function in relation to names, i.e. you can pass arguments in any order and define optional arguments. For example, "array_fill(start_index: 0, num: 100, value: 50)".
  • When calling methods allowed the use of the "?" operator, which allows the call to be initiated only if the method is present, which avoids unnecessary checks for the return of the "null" value. For example, "$dateAsString = $booking->getStartDate()?->asDateTimeString()";
  • Support union types, which define collections of two or more types (for example, "public function foo(Foo|Bar $input): int|float;").
  • Support attributes (annotations) that allow metadata (such as type information) to be attached to classes without using Docblock syntax.
  • Expression support match, which, unlike switch, can return values, support combining conditions, use strict type comparison, and do not require the "break" specification.

    $result = match($input) {
    0 => "hello",
    '1', '2', '3' => "world",
    };

  • Shorthand Syntax class definitions, which allows you to combine the definition of the constructor and properties.
  • New return type βˆ’ static.
  • New type - mixed, which can be used to determine whether a function accepts parameters with different types.
  • Expression throw for exception handling.
  • WeakMap to create objects that can be sacrificed by garbage collection (for example, to store optional caches).
  • Possibility using the "::class" expression for objects (analogous to calling get_class()).
  • Possibility definitions in the catch block of exceptions that are not bound to variables.
  • Possibility leaving a comma after the last element in the function's parameter list.
  • New interface Stringable to identify any string types or data that can be converted to a string (for which the __toString() method is available).
  • New feature str_contains(), a simplified analogue of strpos for detecting the occurrence of a substring, as well as the functions str_starts_with() and str_ends_with() for checking matches at the beginning and end of a string.
  • Feature added fdiv()A that performs a division operation without outputting an error in case of division by zero.
  • Changed string join logic. For example, the expression 'echo "sum: " . $a + $b' was previously interpreted as 'echo ("sum: " . $a) + $b' and will be treated as 'echo "sum: " in PHP 8. ($a + $b)'.
  • Tightened checks for arithmetic and bitwise operations such as "[] % [42]" and "$object + 4" will result in an error.
  • Implemented a stable sorting algorithm that preserves the order of the same values ​​on different runs.
  • Source: opennet.ru

Add a comment