New Features and Changes in PHP 8.5 and OpenSwoole 26.2.0

OpenSwoole Team
Published:

PHP 8.5 introduces powerful new features including the Pipe Operator, a built-in URI extension, Clone With, and more. OpenSwoole 26.2.0 will be released by the end of February 2026 with full PHP 8.5 support.

New Features and Changes in PHP 8.5 and OpenSwoole 26.2.0New Features and Changes in PHP 8.5 and OpenSwoole 26.2.0

Key Features in PHP 8.5

1. Pipe Operator (|>)

PHP 8.4 and earlier: Chaining multiple function calls required deeply nested calls or intermediary variables.

$title = ' PHP 8.5 Released ';

$slug = strtolower(
    str_replace('.', '',
        str_replace(' ', '-',
            trim($title)
        )
    )
);
// string(15) "php-85-released"

PHP 8.5: The pipe operator allows left-to-right chaining for much better readability.

$title = ' PHP 8.5 Released ';

$slug = $title
    |> trim(...)
    |> (fn($str) => str_replace(' ', '-', $str))
    |> (fn($str) => str_replace('.', '', $str))
    |> strtolower(...);
// string(15) "php-85-released"

2. URI Extension

PHP 8.4 and earlier: Parsing URIs relied on the procedural parse_url() function with limited validation.

$components = parse_url('https://php.net/releases/8.5/en.php');
var_dump($components['host']);
// string(7) "php.net"

PHP 8.5: A new built-in URI extension provides a proper object-oriented API following RFC 3986 and WHATWG URL standards.

use Uri\Rfc3986\Uri;

$uri = new Uri('https://php.net/releases/8.5/en.php');
var_dump($uri->getHost());
// string(7) "php.net"

3. Clone With

PHP 8.4 and earlier: Updating properties during cloning required workarounds, especially for readonly classes.

readonly class Color
{
    public function __construct(
        public int $red,
        public int $green,
        public int $blue,
        public int $alpha = 255,
    ) {}

    public function withAlpha(int $alpha): self
    {
        $values = get_object_vars($this);
        $values['alpha'] = $alpha;
        return new self(...$values);
    }
}

$blue = new Color(79, 91, 147);
$transparentBlue = $blue->withAlpha(128);

PHP 8.5: The clone() function now accepts an associative array to update properties during cloning.

readonly class Color
{
    public function __construct(
        public int $red,
        public int $green,
        public int $blue,
        public int $alpha = 255,
    ) {}

    public function withAlpha(int $alpha): self
    {
        return clone($this, ['alpha' => $alpha]);
    }
}

$blue = new Color(79, 91, 147);
$transparentBlue = $blue->withAlpha(128);

4. #[\NoDiscard] Attribute

PHP 8.4 and earlier: There was no way to warn callers when they ignored a function's return value.

function getPhpVersion(): string
{
    return 'PHP 8.4';
}

getPhpVersion(); // No warning, return value silently ignored

PHP 8.5: The #[\NoDiscard] attribute emits a warning when a return value is not used.

#[\NoDiscard]
function getPhpVersion(): string
{
    return 'PHP 8.5';
}

getPhpVersion();
// Warning: The return value of function getPhpVersion() should
// either be used or intentionally ignored by casting it as (void)

(void) getPhpVersion(); // Suppress warning explicitly

5. Closures in Constant Expressions

PHP 8.4 and earlier: Closures could not be used in constant expressions such as attributes or default parameter values.

final class PostsController
{
    #[AccessControl(
        new Expression('request.user === post.getAuthor()'),
    )]
    public function update(Request $request, Post $post): Response
    {
        // ...
    }
}

PHP 8.5: Static closures and first-class callables can now be used in constant expressions.

final class PostsController
{
    #[AccessControl(static function (
        Request $request,
        Post $post,
    ): bool {
        return $request->user === $post->getAuthor();
    })]
    public function update(Request $request, Post $post): Response
    {
        // ...
    }
}

6. New Array Functions

PHP 8.4 and earlier: Getting the first or last element of an array required verbose code.

$lastEvent = $events === []
    ? null
    : $events[array_key_last($events)];

PHP 8.5: New array_first() and array_last() functions simplify array access.

$firstEvent = array_first($events);
$lastEvent = array_last($events);

7. Fatal Error Backtraces

PHP 8.5 now includes stack traces for fatal errors, making it significantly easier to debug issues in production. This is especially useful for OpenSwoole applications where coroutine stack traces can help pinpoint the exact source of a problem.

8. Persistent cURL Share Handles

PHP 8.4 and earlier: cURL share handles had to be recreated for each request.

$sh = curl_share_init();
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_share_setopt($sh, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);

$ch = curl_init('https://php.net/');
curl_setopt($ch, CURLOPT_SHARE, $sh);
curl_exec($ch);

PHP 8.5: Persistent share handles allow connection reuse across requests.

$sh = curl_share_init_persistent([
    CURL_LOCK_DATA_DNS,
    CURL_LOCK_DATA_CONNECT,
]);

$ch = curl_init('https://php.net/');
curl_setopt($ch, CURLOPT_SHARE, $sh);
// May reuse connection from earlier request
curl_exec($ch);

OpenSwoole 26.2.0 with PHP 8.5 Support

OpenSwoole 26.2.0 will be released by the end of February 2026 with full PHP 8.5 support. Stay tuned for the official release announcement.