========================================
New Features
========================================
- Core:
. Added support for union types.
RFC:
https://wiki.php.net/rfc/union_types_v2
. Added WeakMap.
RFC:
https://wiki.php.net/rfc/weak_maps
. Added ValueError class.
. Any number of function parameters may now be replaced by a variadic
argument, as long as the types are compatible. For example, the following
code is now allowed:
Code (PHP8)
class A {
public function method(int $many, string $parameters, $here) {}
}
class B extends A {
public function method(...$everything) {}
}
. "static" (as in "late static binding") can now be used as a return type:
Code (PHP8)
class Test {
public function create(): static {
return new static();
}
}
RFC:
https://wiki.php.net/rfc/static_return_type
. It is now possible to fetch the class name of an object using
`$object::class`. The result is the same as `get_class($object)`.
RFC:
https://wiki.php.net/rfc/class_name_literal_on_object
. New and instanceof can now be used with arbitrary expressions, using
`new (expression)(...$args)` and `$obj instanceof (expression)`.
RFC:
https://wiki.php.net/rfc/variable_syntax_tweaks
. Some consistency fixes to variable syntax have been applied, for example
writing `Foo::BAR::$baz` is now allowed.
RFC:
https://wiki.php.net/rfc/variable_syntax_tweaks
. Added Stringable interface, which is automatically implemented if a class
defines a __toString() method.
RFC:
https://wiki.php.net/rfc/stringable
. Traits can now define abstract private methods.
RFC:
https://wiki.php.net/rfc/abstract_trait_method_validation
. `throw` can now be used as an expression.
RFC:
https://wiki.php.net/rfc/throw_expression
. An optional trailing comma is now allowed in parameter lists.
RFC:
https://wiki.php.net/rfc/trailing_comma_in_parameter_list
. It is now possible to write `catch (Exception)` to catch an exception
without storing it in a variable.
RFC:
https://wiki.php.net/rfc/non-capturing_catches
. Added support for mixed type
RFC:
https://wiki.php.net/rfc/mixed_type_v2
. Added support for Attributes
RFC:
https://wiki.php.net/rfc/attributes_v2
RFC:
https://wiki.php.net/rfc/attribute_amendments
RFC:
https://wiki.php.net/rfc/shorter_attribute_syntax
. Added support for constructor property promotion (declaring properties in
the constructor signature).
RFC:
https://wiki.php.net/rfc/constructor_promotion
. Added support for `match` expression.
RFC:
https://wiki.php.net/rfc/match_expression_v2
. Private methods declared on a parent class no longer enforce any
inheritance rules on the methods of a child class. (with the exception of
final private constructors)
RFC:
https://wiki.php.net/rfc/inheritance_private_methods
. Added support for nullsafe operator (`?->`).
RFC:
https://wiki.php.net/rfc/nullsafe_operator
. Added support for named arguments.
RFC:
https://wiki.php.net/rfc/named_params
- Date:
. Added DateTime::createFromInterface() and
DateTimeImmutable::createFromInterface().
. Added the DateTime format specifier "p" which is the same as "P" but
returning "Z" for UTC.
- Dom:
. Introduce DOMParentNode and DOMChildNode with new traversal and
manipulation APIs.
RFC:
https://wiki.php.net/rfc/dom_living_standard_api
- Enchant:
. enchant_dict_add()
. enchant_dict_is_added()
. LIBENCHANT_VERSION macro
- FPM:
. Added a new option pm.status_listen that allows getting status from
different endpoint (e.g. port or UDS file) which is useful for getting
status when all children are busy with serving long running requests.
- Hash:
. HashContext objects can now be serialized.
- Opcache:
. If the opcache.record_warnings ini setting is enabled, opcache will record
compile-time warnings and replay them on the next include, even if it is
served from cache.
- OpenSSL:
. Added Cryptographic Message Syntax (CMS) (RFC 5652) support composed of
functions for encryption, decryption, signing, verifying and reading. The
API is similar to the API for PKCS #7 functions with an addition of new
encoding constants: OPENSSL_ENCODING_DER, OPENSSL_ENCODING_SMIME and
OPENSSL_ENCODING_PEM.
- Standard:
. printf() and friends now support the %h and %H format specifiers. These
are the same as %g and %G, but always use "." as the decimal separator,
rather than determining it through the LC_NUMERIC locale.
. printf() and friends now support using "*" as width or precision, in which
case the width/precision is passed as an argument to printf. This also
allows using precision -1 with %g, %G, %h and %H. For example, the following
code can be used to reproduce PHP's default floating point formatting:
Code (PHP8)
printf("%.*H", (int) ini_get("precision"), $float);
printf("%.*H", (int) ini_get("serialize_precision"), $float);
. proc_open() now supports pseudo-terminal (PTY) descriptors. The following
attaches stdin, stdout and stderr to the same PTY:
Code (PHP8)
$proc = proc_open($command, [['pty'], ['pty'], ['pty']], $pipes);
. proc_open() now supports socket pair descriptors. The following attaches
a distinct socket pair to stdin, stdout and stderr:
Code (PHP8)
$proc = proc_open(
$command, [['socket'], ['socket'], ['socket']], $pipes);
Unlike pipes, sockets do not suffer from blocking I/O issues on Windows.
However, not all programs may work correctly with stdio sockets.
. Sorting functions are now stable, which means that equal-comparing elements
will retain their original order.
RFC:
https://wiki.php.net/rfc/stable_sorting
- Zip:
. Extension updated to version 1.19.0
. New ZipArchive::lastId property to get index value of last added entry.
. Error can be checked after an archive is closed using ZipArchive::status,
ZipArchive::statusSys properties or ZipArchive::getStatusString() method.
. The remove_path option of ZipArchive::addGlob() and ::addPattern() is now
treated as arbitrary string prefix (for consistency with the add_path
option), whereas formerly it was treated as directory name.
. Optional compression / encryption features are listed in phpinfo.