New Features
PHP Core
Default values for readonly properties
Readonly
properties, including those of
readonly classes,
may now declare default values.
The default value counts as the initialization of the property, so the
property cannot be assigned again, not even from the constructor.
Reference assignment on WeakMap
It is now possible to use reference assignment on a
WeakMap without the key needing to be present
beforehand.
__debugInfo on enums
It is now possible to define the
__debugInfo()
magic method on enums.
Previously, this resulted in a fatal error.
#[\Override] for class constants
The Override attribute can now be applied to
class constants, including enum cases.
As with methods and properties, a compile-time error is raised if no
matching constant exists in a parent class or implemented interface.
Partial function application
Added support for
partial function application.
A call in which one or
more arguments are replaced by the ? placeholder, or
the remaining arguments by the ... placeholder,
creates a Closure that accepts the missing
arguments.
Mutating objects stored in constants
Objects stored in constants or class constants can now be mutated
directly via OBJ->prop = $val.
Endianness modifiers for pack() and unpack()
pack and unpack now accept the
< (little-endian) and >
(big-endian) modifiers after the s, S,
l, L, q and
Q integer format codes, and after the
f and d float and double format codes.
cURL
The array returned by curl_getinfo now includes a new
"size_delivered" key, which indicates the total number of
bytes passed to the download write callback.
This value can also be obtained by passing
CURLINFO_SIZE_DELIVERED as the
option parameter.
Requires libcurl 8.20.0 or later.
Added CURLOPT_SEEKFUNCTION to register a callback that
repositions a streamed request body, so libcurl can rewind and resend it on
a redirect, multi-pass authentication, or a retried reused connection
instead of failing with CURLE_SEND_FAIL_REWIND.
The callback receives the CurlHandle, offset and
origin, and must return one of CURL_SEEKFUNC_OK,
CURL_SEEKFUNC_FAIL or
CURL_SEEKFUNC_CANTSEEK.
Date
Added the Time\Duration class to represent a fixed
length of elapsed time, such as a timeout, with nanosecond precision.
Unlike DateInterval, it has no calendar units such
as days or months, so its length is unambiguous.
Durations are immutable and can be compared with the comparison
operators. The class provides:
-
Factory methods such as
Time\Duration::fromSeconds,
Time\Duration::fromMilliseconds and
Time\Duration::fromIso8601DurationString
-
Arithmetic with Time\Duration::add,
Time\Duration::sub,
Time\Duration::multiplyBy and
Time\Duration::divideBy
-
Time\Duration::negate and
Time\Duration::absolute to change the sign
-
Time\Duration::compare for use as a sorting
callback
A Time\TimeException is thrown when a
duration exceeds the representable range of roughly 292 years, or when an
ISO 8601 duration string is invalid.
FileInfo
finfo_file now works with remote streams.
GMP
Added gmp_powm_sec for side-channel quiet modular
exponentiation.
Requires GNU MP 5.0.0 or later; it is not available on official Windows
builds using MPIR.
Added gmp_prevprime to get the largest prime smaller
than the given number.
The optional definitely_prime output parameter
indicates whether the returned number is definitely prime, as opposed to
probably prime.
A ValueError is thrown if no such prime
exists.
This function is only available when PHP is built against GNU MP 6.3.0 or
later; it is not available on official Windows builds using MPIR.
Intl
Added the static methods
IntlDatePatternGenerator::getSkeleton and
IntlDatePatternGenerator::getBaseSkeleton to
generate the unique skeleton and base skeleton for a date/time pattern.
Added Locale::getDisplayKeyword and
Locale::getDisplayKeywordValue, with the aliases
locale_get_display_keyword and
locale_get_display_keyword_value, respectively.
Added the IntlNumberRangeFormatter class to format
an interval of two numbers with a given skeleton and locale.
It is supported as of ICU 63.
The collapse behavior is one of:
IntlNumberRangeFormatter::COLLAPSE_AUTO
IntlNumberRangeFormatter::COLLAPSE_NONE
IntlNumberRangeFormatter::COLLAPSE_UNIT
IntlNumberRangeFormatter::COLLAPSE_ALL
The identity fallback is one of:
IntlNumberRangeFormatter::IDENTITY_FALLBACK_SINGLE_VALUE
IntlNumberRangeFormatter::IDENTITY_FALLBACK_APPROXIMATELY_OR_SINGLE_VALUE
IntlNumberRangeFormatter::IDENTITY_FALLBACK_APPROXIMATELY
IntlNumberRangeFormatter::IDENTITY_FALLBACK_RANGE
Added SpoofChecker::areBidiConfusable to check
whether two strings are confusable for a given text direction, along with
the SpoofChecker::LTR and
SpoofChecker::RTL direction constants.
It is supported as of ICU 74.
Added SpoofChecker::getBidiSkeleton to generate a
confusable skeleton for a given text direction.
It is supported as of ICU 74.
Added SpoofChecker::getSkeleton to generate a
confusable skeleton for a given string.
IO
Added a new polling API, consisting of:
- The Io\Poll\Context and Io\Poll\Watcher classes
- The Io\Poll\Backend and Io\Poll\Event enums
- The Io\Poll\Handle interface
- The StreamPollHandle class to watch streams
JSON
Added extra information about the error location to the error messages
returned by json_last_error_msg and to the message of
JsonException.
OpenSSL
Added TLS session resumption support for streams.
This allows saving and restoring client sessions across requests,
implementing custom server-side session storage, and controlling session
cache behavior, using the following new
SSL context options:
session_data
session_new_cb
session_cache
session_cache_size
session_timeout
session_id_context
session_get_cb
session_remove_cb
num_tickets
Added TLS external PSK support for
streams with the new SSL context
options psk_client_cb and
psk_server_cb.
This allows setting and receiving pre-shared keys.
Added TLS 1.3 early data (0-RTT) support for streams.
Clients send early data with the early_data
SSL context option; servers accept it
with max_early_data and receive it through the
early_data_cb callback.
The outcome is reported as "accepted",
"rejected" or "not_sent" in the
"early_data" key of the "crypto"
entry of the stream_get_meta_data array.
PDO_PGSQL
Added Pdo\Pgsql::ATTR_CHUNK_SIZE, the number of rows a
statement fetches per chunk.
A value of 1 or more enters the lazy fetch mode of
PDO::ATTR_PREFETCH => 0.
Setting PDO::ATTR_PREFETCH replaces the chunk size.
Statements that are prepared with neither it nor
PDO::ATTR_PREFETCH fall back to the value set on the
connection.
Requires libpq 17 or later.
Phar
Overriding the SplFileInfo::getMTime and
SplFileInfo::getPathname methods now influences
the result of the Phar::buildFromDirectory and
Phar::buildFromIterator family of methods.
This makes it possible to override the timestamp and names of files.
SNMP
It is now possible to use AES192,
AES192C, AES256, and
AES256C as SNMPv3 security protocols if the underlying
library supports them.
It is now possible to reset the MIB tree using the new
snmp_init_mib function.
Additional MIB parsing and output control functionality
has been exposed via:
- snmp_set_mib_option
- snmp_set_output_option
- snmp_set_string_output_format
- SNMP::$numeric_index
- SNMP::$numeric_timeticks
- SNMP::$extended_index
- SNMP::$dont_print_units
- SNMP::$escape_quotes
- SNMP::$print_hex_text
- SNMP::setOidOutputFormat
- SNMP::setStringOutputFormat
SOAP
Added the "keep_headers" option to
SoapClient::__construct to specify which
HTTP headers a SoapClient should
keep when importing a WSDL from a host different from
the original one.
By default, the Authorization,
Proxy-Authorization, and Cookie
headers are redacted on such requests.
The option accepts an array of header names to keep, for example
['keep_headers' => ['authorization']].
Streams
Added a new stream errors API, consisting of:
- The StreamError and StreamException classes
- The StreamErrorStore, StreamErrorMode, and StreamErrorCode enums
- The stream_last_errors and stream_clear_errors functions
It is controlled using the
error_mode,
error_store and
error_handler
stream context options.
See
Stream Errors for an overview.
Added the filter.max_filter_count stream context option
for php://filter URLs.
When set, opening the stream fails with a warning if the URL would add more
filters than the configured value.
Negative values disable the check.
Added the socket context option
so_reuseaddr that allows disabling address reuse
(SO_REUSEADDR) and explicitly uses
SO_EXCLUSIVEADDRUSE on Windows.
Added the socket context options
so_keepalive, tcp_keepidle,
tcp_keepintvl and tcp_keepcnt that
allow setting socket keepalive options.
Added the socket context option
so_linger that sets SO_LINGER on
TCP sockets.
A positive value enables lingering for that many seconds, zero or a
negative value disables it.
Values above 65535 are clamped as the linger time is limited to an
unsigned short on some platforms.
Added the socket context options
so_rcvbuf and so_sndbuf that set the
socket receive and send buffer sizes in bytes
(SO_RCVBUF and SO_SNDBUF) on
TCP and UDP sockets.
The value must be an integer between 1 and 2147483647, any other value
makes the stream creation fail.
The operating system may round, cap or otherwise adjust the requested size,
and may stop sizing that buffer automatically, so the size read back can
differ from the one requested.
Filtered streams can now be cast to file descriptors for use with
stream_select.
Added the "write_seek_mode" filter parameter for the
bz2, iconv, zlib, and convert stream
filters.
This parameter must be set via an associative array where the key is
"write_seek_mode" and the value is one of the following
strings:
"preserve"
"reset"
"strict"
URI
Added Uri\Rfc3986\Uri::getUriType and
Uri\WhatWg\Url::isSpecialScheme.
Added Uri\Rfc3986\Uri::getHostType and
Uri\WhatWg\Url::getHostType.
Added the Uri\Rfc3986\UriBuilder and
Uri\WhatWg\UrlBuilder classes.
Added Uri\WhatWg\url_percent_encode.