This major release brings a series of new features, syntax improvements, and performance optimizations driven by RFCs, aiming to enhance development efficiency, code readability, and program robustness.
According to online blog posts, one of the most significant highlights of the new version is the introduction of a brand-new built-in URI extension. Built on uriparser and Lexbor, this extension provides a unified and powerful API for parsing and modifying URLs.
It adheres to both RFC 3986 and WHATWG URL standards, and in scenarios requiring high-precision, standards-compliant URL processing, it can replace the original parse_url function, ensuring operational accuracy.
To optimize code readability and maintainability, PHP 8.5 officially added the pipe operator (|>). This operator allows developers to build left-to-right function chaining calls, directly using the output of one function as the input of the next. This approach completely changes the previous deeply nested function call syntax, making the data processing flow clear and the code structure flatter and more concise.
In terms of object handling, the new version introduces the clone-with syntax. Developers can now clone an object and update its specified properties simultaneously using the expression `clone ($obj, ['prop' => value])`. This feature not only simplifies the implementation of the common "with-er" pattern but also allows its use in read-only classes without writing additional template code.
To help developers catch potential coding errors, PHP 8.5 adds the `#[\NoDiscard]` attribute. A warning is issued when the return value of a function marked with this attribute is unintentionally ignored.
This effectively prevents program logic errors caused by forgetting to handle critical return values. If developers do need to discard the return value, they can explicitly declare it using `(void)` to eliminate the warning.
Furthermore, this update also includes performance optimizations, new helper functions, and several syntax improvements. For example, persistent cURL shared handles reduce the resident overhead of long-running applications by reusing connection data across multiple requests.
The `array_first` and `array_last` functions simplify the operation of retrieving the first and last elements of an array. In addition, the new version adds backtracking for fatal errors, expands the scope of attribute usage, and deprecates some old features to guide developers toward more modern and safer programming practices.
