PHP 8.5 explained: pipe, clone, arrays and URIs
Features of PHP 8.5, released November 20, 2025, with examples and compatibility checks before upgrading.
Features of PHP 8.5, released November 20, 2025, with examples and compatibility checks before upgrading.
Version and compatibility
PHP 8.5 was released on November 20, 2025. Moving from 8.4 to 8.5 changes the minor version, not the first digit. Before updating a production site, check framework, extensions and hosting requirements, read the migration guide, test code and plugins in staging, and prepare a backup and rollback.
Pipe operator
The |> operator passes a value through callables from left to right. In the example trim(...) and strtolower(...) are first-class callables; the closure receives the previous result. The right side must be callable rather than an arbitrary expression. It can make multistep transformations easier to read.
<?php
$title = ' PHP 8.5 Released ';
$slug = $title |> trim(...) |> (fn($s) => str_replace(' ', '-', $s)) |> strtolower(...);
var_dump($slug); // string(16) "php-8.5-released"
Clone with modified properties
clone($object, ['property' => value]) creates a copy while assigning properties, including in readonly classes. The example changes alpha in the copy but not the original. This differs from cloning and then assigning a property, which cannot rewrite an initialized readonly property.
<?php
readonly class Color {
public function __construct(public int $red, public int $alpha = 255) {}
public function withAlpha(int $alpha): self {
return clone($this, ['alpha' => $alpha]);
}
}
$original = new Color(79);
$copy = $original->withAlpha(128);
First and last array values
array_first() and array_last() return values in array order, not by smallest or largest key. They return null for an empty array; if null can also be a stored value, check emptiness separately. They do not move the internal pointer like reset() and end().
<?php
$items = ['first', 'middle', 'last'];
var_dump(array_first($items)); // "first"
var_dump(array_last($items)); // "last"
var_dump(array_first([])); // null
URI extension
Uri\Rfc3986\Uri parses according to RFC 3986; PHP 8.5 also has APIs for the WHATWG URL model. Choose the model for your use case. The extension does not automatically remove the need for external libraries, URL validation, host checks or security controls around remote requests.
<?php
use Uri\Rfc3986\Uri;
$uri = new Uri('https://example.com/path?q=1');
var_dump($uri->getHost()); // "example.com"
Deprecations and upgrade
Noncanonical casts (boolean), (integer), (double) and (binary) are deprecated; use (bool), (int), (float) and (string). Backticks as a shell_exec() alias are also deprecated. shell_exec() is more explicit, not safer for untrusted input: avoid shell commands where possible and never concatenate external values. Review warnings and incompatibilities in the migration guide.
Official sources
Release: https://www.php.net/releases/8.5/en.php ; functions: https://www.php.net/manual/en/migration85.new-functions.php ; deprecations: https://www.php.net/manual/en/migration85.deprecated.php ; migration: https://www.php.net/manual/en/migration85.php .
Share
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0