PHP 8.5 New Features: Pipe Operator and URI Extension
PHP got updated in version 8.5 with a bunch of new smart features. Especially the new URI extension and the pipe operator are worth a look.
The New URI Extension
<?php
##### URI Extension #####
// PHP 8.4 way
$components = parse_url('https://php.net/releases/8.4/en.php');
var_dump($components['host']);
// string(7) "php.net"
// PHP 8.5 URI Extension
use Uri\Rfc3986\Uri;
$uri = new Uri('https://php.net/releases/8.5/en.php');
var_dump($uri->getHost());
// string(7) "php.net"
The New Pipe Operator
<?php
##### Pipe Operator #####
// PHP 8.4 way
$title = ' PHP 8.5 Released ';
$slug = strtolower(
str_replace('.', '',
str_replace(' ', '-',
trim($title)
)
)
);
var_dump($slug);
// string(15) "php-85-released"
// PHP 8.5 Pipe Operator
$title = ' PHP 8.5 Released ';
$slug = $title
|> trim(...)
|> (fn($str) => str_replace(' ', '-', $str))
|> (fn($str) => str_replace('.', '', $str))
|> strtolower(...);
var_dump($slug);
// string(15) "php-85-released"
PHP got updated in version 8.5 with a bunch of new smart features. Especially the new URI extension and the pipe operator are worth a look.
Additional Resources
- You can find more new PHP functions and examples here: https://www.php.net/releases/8.5/en.php
- PHP 8.5 changelog: https://www.php.net/ChangeLog-8.php#PHP_8_5
- Installation and update instructions for various operating systems: https://www.php.net/downloads
Ihre Drupal-Website zukunftssicher machen
Wir prüfen Ihr System und zeigen, was Sie für AI, Wartung und Upgrades brauchen.