the first beta release of the new branch of the PHP 8 programming language. The release is scheduled for November 26. At the same time, corrective releases of PHP 7.4.9, 7.3.21 and
7.2.33, in which accumulated errors and vulnerabilities have been fixed.
Key PHP 8:
- , whose implementation will increase performance.
- named function arguments, allowing values to be passed to a function bound by names, meaning arguments can be passed in any order and optional arguments can be defined. For example, "array_fill(start_index: 0, num: 100, value: 50)".
- When calling methods using the "?" operator, which allows the invocation to be initiated only if the method exists, thus avoiding unnecessary checks for a "null" return value. For example, "$dateAsString = $booking->getStartDate()?->asDateTimeString()";
- Support , defining collections of two or more types (for example, 'public function foo(Foo|Bar $input): int|float;').
- Support (annotations) that allow binding metadata (e.g., type information) to classes without using the Docblock syntax.
- Support for expressions , which unlike switch can return values, support condition combination, use strict type comparison, and do not require specifying "break".
$result = match($input) {
0 => "hello",
'1', '2', '3' => "world",
}; - for class definitions, allowing the constructor and property definitions to be combined.
- A new return type — .
- The new type — , which can be used to define a function's acceptance of parameters of different types.
- Expression for handling exceptions.
- for creating objects that can be garbage collected (for example, for storing optional caches).
- using the expression '::class' for objects (similar to calling get_class()).
- definitions in the catch block of exceptions not bound to variables.
- leaving a comma after the last element in a function parameter list.
- better matches the browser interface. Support for AcroForm (form filling will be included later, activated via the setting pdfjs.renderInteractiveForms) has been added. to identify any string types or data that can be converted to a string (for which the method __toString() is available).
- A new function , a simplified equivalent of strpos for determining substring presence, as well as the functions str_starts_with() and str_ends_with() for checking matches at the beginning and end of a string.
- A function has been added , which performs division without throwing an error in the case of division by zero.
- the logic for string concatenation. For example, the expression 'echo "sum: " . $a + $b' was previously interpreted as 'echo ("sum: " . $a) + $b', whereas in PHP 8 it will be processed as 'echo "sum: " . ($a + $b)'.
- checks for arithmetic and bitwise operations, for example, the expressions '[] % [42]' and '$object + 4' will result in an error.
- a stable sorting algorithm, in which the order of identical values is preserved across different runs.
Source: opennet.ru
