Newshot

What's New in PHP 8.6

Original text(via Hacker News)

Additional Features and Improvements

  • The #[\Override] attribute can now be applied to class constants and enum cases.
  • Enums can now implement the __debugInfo() magic method.
  • Properties of objects stored in constants can now be modified directly, e.g. Config::DEFAULTS->timeout = 30.
  • New Uri\Rfc3986\UriBuilder and Uri\WhatWg\UrlBuilder classes build URIs from their components, along with new methods for detecting URI and host types and a Uri\WhatWg\url_percent_encode() function.
  • The Sodium extension adds post-quantum key encapsulation (X-Wing and ML-KEM-768), IP address encryption, and the SHAKE and TurboSHAKE extendable-output functions.
  • TLS streams now support session resumption, external pre-shared keys, and TLS 1.3 early data (0-RTT).
  • New mysqli::quote_string() method escapes a string and wraps it in quotes, matching PDO::quote().
  • pack() and unpack() now accept the < and > endianness modifiers on integer and float format codes.
  • JSON error messages now include the location of the error in the input.
  • The new error_include_args INI setting consistently includes function arguments in error messages.
  • New grapheme_strrev() function reverses strings by grapheme cluster, and the new IntlNumberRangeFormatter class formats ranges of numbers.
  • New ZipArchive::openString() and ZipArchive::closeString() methods work with in-memory archives.
  • Performance improvements include compiling array_map() with first-class callable or partial application callbacks into loops, faster printf() calls, caching of stateless closures, and faster JSON encoding.

Deprecations and Backward Compatibility Breaks

  • Using return inside a finally block is now deprecated, as it silently discards exceptions and overrides values returned from the try or catch block.
  • Returning a value from __construct() or __destruct() is now deprecated, as is making them generators. Declaring a nullable return type for __debugInfo() is also deprecated.
  • Using let or is as the name of a class, function, or constant is now deprecated. Using _ as a constant name, namespace as a class constant name, or readonly as a function name is also deprecated.
  • The mbstring regular expression functions such as mb_ereg() and mb_split() have been deprecated, as the underlying Oniguruma library is no longer maintained. PCRE functions with the u modifier can be used instead.
  • The is_double(), is_long(), is_integer(), and doubleval() aliases have been deprecated. Use is_float(), is_int(), and floatval() instead.
  • spl_object_hash() has been deprecated in favor of spl_object_id(), and spl_classes() in favor of ReflectionExtension::getClassNames().
  • Passing an object where an array is expected to array_walk(), array_walk_recursive(), http_build_query(), mb_convert_variables(), and compression functions and filters is now deprecated. Use get_object_vars() to convert the object first.
  • strcoll() and the SORT_LOCALE_STRING sort flag have been deprecated. Use the Collator class from the intl extension instead.
  • Passing a third argument to define() is now deprecated, as is calling is_a() or is_subclass_of() with a class name string when $allow_string is false.
  • Using more than 16 filters in a php://filter URL without setting the filter.max_filter_count context option is now deprecated.
  • Sessions are now more secure by default: session.use_strict_mode and session.cookie_httponly are enabled, and session.cookie_samesite is set to Lax.
  • Custom session handlers that do not implement both create_sid() and validateId() are now deprecated.
  • The metaphone(), mysqli_get_charset(), and mysqli_stmt_init() functions are now deprecated, along with the CSV methods of SplFileObject and the sorting, flag, and serialization methods of ArrayIterator.
  • trim(), ltrim(), and rtrim() now also strip form feed (\f) characters by default.
  • fclose(), file_put_contents(), and copy() now return false when flushing or closing the stream fails, instead of silently ignoring the failure.
  • Many functions now throw a ValueError for out-of-range values, invalid flags, or strings containing NUL bytes, instead of silently truncating or ignoring them.

The text above was extracted automatically from the source page and may miss images, tables or code blocks. The original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗