DEV Community

ServBay
ServBay

Posted on

PHP 8.5 Coming Soon: Pipe Operator, Powerful Debugging

Not long ago, PHP announced the official release of PHP 8.5, scheduled for November 20, 2025! As another significant iteration of the PHP language, PHP 8.5 promises a series of improvements aimed at enhancing code readability, robustness, and developer efficiency. And what's even more exciting is that with the powerful local development environment ServBay, we can now "get a head start" and experience the charm of the PHP 8.5-dev version in advance!

PHP 8.5 will continue to enjoy two years of active support and two years of security fixes, until December 31, 2029. This means it will be an indispensable part of our work for years to come. So, what surprises will PHP 8.5 bring us? Let's dive in and find out!

Image description

PHP 8.5 Core Language Improvements: More Elegant, More Powerful

PHP 8.5 brings some very practical enhancements at the core language level, making our code more modern and easier to maintain.

1. Pipe Operator (|>): Say Goodbye to Nesting, Embrace Fluidity

This is definitely one of the most anticipated features in PHP 8.5! The pipe operator (|>) allows us to chain function calls in a clearer, more intuitive way.

Previously, processing a series of operations might look like this:

$result = trim(str_shuffle(strtoupper("Hello World"))); echo $result; 
Enter fullscreen mode Exit fullscreen mode

This nested style can drastically reduce readability as the number of function calls increases.

Now, with the pipe operator, the code can look like this:

$result = "Hello World" |> strtoupper(...) // strtoupper() will receive "Hello World" as its first argument |> str_shuffle(...) // str_shuffle() will receive the result of strtoupper() |> trim(...); // trim() will receive the result of str_shuffle() echo $result; 
Enter fullscreen mode Exit fullscreen mode

Doesn't the code's execution flow feel crystal clear? From left to right, data flows smoothly through each processing step like a stream, greatly enhancing readability and maintainability!

2. Attributes (Marking Important Return Values): Avoid Hidden Errors

Have you ever encountered a situation where you called a function but forgot to use its return value, leading to unexpected program behavior? The attribute introduced in PHP 8.5 (the specific RFC name might be [MarkAsUsed] or something similar; here we follow the description provided in the material) is designed to solve such problems.

This attribute can be used to mark functions or methods whose return values are crucial. If you call a function marked with this attribute but don't use its return value, PHP will issue a warning at compile-time or runtime.

A typical example is the file locking operation flock(). The return value of flock() indicates whether the operation was successful. If this return value is ignored, it can lead to data race conditions in concurrent scenarios. With this attribute, compilers or static analysis tools can promptly remind us to handle the return values of such critical functions, helping us write more robust code.

3. Attributes on Constants: A New Dimension for Metadata

Now, we can add attributes (metadata) to constants defined with const. This opens up more possibilities for code reflection and static analysis, allowing frameworks and libraries to understand and utilize constants more intelligently.

4. Asymmetric Visibility for Static Properties: Finer-Grained Access Control

PHP 8.5 allows us to set different visibility levels for reading and writing static class properties. For example, you can make a static property publicly readable but only allow it to be modified from within the class. This finer-grained control helps to better encapsulate and protect class state.

5. First-Class Callables and Closures in Constant Expressions: Flexibility Upgraded Again

This is a fantastic improvement! You can now use Closures and first-class callables in constant expressions, for example, as default values for function parameters. This will make code design more flexible and concise, especially when defining configurable behaviors.

New Functions & API Enhancements: Boosting Efficiency and Standards

PHP 8.5 also brings a batch of practical new functions and API improvements.

  • array_first() and array_last() functions: Finally, an official way to directly get the first and last elements of an array, without worrying about the side effects of reset() or end() changing the array's internal pointer.
  • get_error_handler() and get_exception_handler() functions: Conveniently retrieve the currently set error and exception handlers, very useful for debugging, logging, and custom error handling flows.
  • URL API compliant with RFC 3986 and WHATWG standards: PHP 8.5 will introduce a brand-new URL processing API that more strictly adheres to modern web standards, enabling more reliable and accurate parsing and manipulation of URLs, saying goodbye to some of the pitfalls of the old parse_url().
  • grapheme_levenshtein() function: For applications dealing with multilingual text, this function is very practical. It calculates the Levenshtein distance of strings based on "grapheme clusters" (user-perceived characters, e.g., a letter with a diacritic), which is more accurate than traditional byte-based or character-based comparisons.
  • Persistent cURL shared handles: For applications that frequently make cURL requests (like API gateways, microservice communication), this feature allows cURL connections to be reused across multiple PHP requests (via curl_share_init(), etc.), significantly reducing connection establishment overhead and improving performance.

Developer Experience & Debugging Improvements: Smoother Development

The PHP team has also been continuously working to improve the daily experience for developers.

  • Enhanced Fatal Error Backtrace: When a fatal error occurs, PHP 8.5 will provide a full stack backtrace by default. This means locating the source and call path of an error will become much easier, greatly simplifying the debugging process.
  • Directory Class Behavior as Resource Object: The Directory class (obtained via the dir() function) will behave more like a standard PHP object rather than a traditional resource type. For example, you can no longer directly use new Directory() to create an instance. This makes the language internally more consistent.
  • New CLI php --ini=diff option: This command-line option is very cool! It can quickly list all configuration items that differ from PHP's default php.ini settings, which is very convenient for troubleshooting environment configuration issues and comparing differences between environments.

Easily Try Out PHP 8.5-dev with ServBay

Seeing all this, are you eager to get your hands on these new features? But you'd have to wait half a year for PHP 8.5 to go live. However, if you have ServBay installed, you can try them out right away, because it supports PHP 8.5-dev!

Image description

ServBay is a powerful, easy-to-use integrated web development environment designed specifically for macOS. It's more than just a simple MAMP/XAMPP replacement; it offers unprecedented flexibility and convenience:

  • One-click installation and switching of PHP versions: ServBay comes with multiple PHP versions, from PHP 5.6 to the latest PHP 8.5-dev. More importantly, it will promptly follow up and support the latest PHP 8.5-dev versions! You can install and switch versions with just a click in ServBay's interface, no compilation headaches.
  • Multiple PHP versions coexisting: You can run multiple different PHP versions simultaneously in ServBay, assigning different PHP versions to different projects without interference.
  • Complete development suite: Besides PHP, ServBay integrates Nginx, MariaDB, PostgreSQL, Redis, Memcached, Node.js, and other common services, creating a one-stop local development environment for you.
  • Independent process management and high performance: Each service runs as an independent user, ensuring security and stability. Meanwhile, ServBay is meticulously optimized for excellent performance.
  • Clean and intuitive graphical interface: All operations can be done through a friendly GUI, making it easy for even beginners to get started quickly.

With ServBay, experiencing PHP 8.5-dev becomes incredibly simple. Just download and install ServBay, then select and start PHP 8.5-dev in the service management to begin your exploration. We strongly recommend everyone to download ServBay (https://www.servbay.com) and try these new features firsthand!

Backward Incompatible Changes & Deprecations: Please Note Before Upgrading

Every PHP version upgrade comes with some backward incompatible changes (BC breaks) and feature deprecations, and PHP 8.5 is no exception. When planning your upgrade, be sure to pay attention to the following points:

  • The pipe operator (|>) is new syntax and will cause parsing errors in older PHP versions.
  • If your project has globally scoped functions with the same names as the new array_first() or array_last() functions, conflicts may arise.
  • All MHASH_* constants have been officially deprecated. Please migrate to using the hash() function family.
  • Some other features, such as changes in the behavior of certain parameters for the openssl_pkey_derive() function, the removal of the intl.error_level INI setting, and the use of FILTER_DEFAULT in filter_*() functions, have also been marked for removal in PHP 9.0. It's advisable to plan ahead.

Before upgrading, be sure to read the official migration guide thoroughly and conduct comprehensive testing on your codebase.

Conclusion & Outlook: PHP 8.5, Steadily Moving Forward

The release of PHP 8.5, while perhaps not bringing disruptive performance leaps like PHP 7.0 (huge performance jump) or PHP 8.0 (JIT compiler), makes the PHP language more modern, robust, and user-friendly through a series of carefully polished language features, API enhancements, and developer experience improvements.

These new features, especially the pipe operator and attributes, will help us write clearer, more reliable, and more maintainable code, thereby improving overall development efficiency and software quality.

Now is the perfect time to start paying attention to PHP 8.5, learn about its new features, and prepare for future upgrades. And ServBay is undoubtedly your best partner for exploring the new world of PHP 8.5 and staying at the forefront of technology. Get moving, join hands with ServBay, and be among the first to experience the charm of future PHP!

Thanks for reading! If you have any questions or thoughts about PHP 8.5 or ServBay, feel free to leave a comment and discuss!

Top comments (0)