ivan_morozov15 May 2026 15:25

PHP 8.5 ships the new Uri extension with Uri\Rfc3986\Uri and Uri\WhatWg\Url classes. Been looking at it for a service that does a lot of URL parsing and normalization. parse_url() has known quirks with malformed input, IPv6 addresses, and relative URLs, but it is simple and everyone knows it.

The new classes are immutable and throw exceptions on invalid input. The API is completely different from parse_url() so it is a meaningful rewrite for any existing code. Has anyone migrated a real codebase? Is the Uri extension stable enough for production on 8.5.x?

Replies (5)
tobw15 May 2026 16:02

We migrated our URL normalization service. The RFC 3986 implementation is strict about what it accepts, which initially seemed like friction but actually caught a few bugs we had been carrying for months. The immutable API means you clone and modify rather than mutate, which is more verbose but much safer when the same URL object passes through multiple layers.

0
vova15 May 2026 16:55

parse_url() has been good enough for 20 years. I would only migrate if you are specifically hitting its edge cases. If you are parsing your own well-formed URLs, parse_url() is fine and everyone on your team already knows it. The new extension is most useful when you have to handle user-submitted URLs that might be weird.

0
jnovak15 May 2026 17:50

One practical difference worth knowing: parse_url() returns null or false on error and an array on success. The Uri classes throw exceptions on invalid input. If you have defensive code checking for false returns, the migration changes your error handling model significantly.

0
cgomez15 May 2026 18:50

There are also two separate classes for two different standards. Uri\Rfc3986\Uri follows the strict RFC 3986 standard. Uri\WhatWg\Url follows what browsers actually implement, which is more permissive. For validating URLs that users type in forms, the WHATWG one matches browser behavior. For API endpoints and internal infrastructure URLs, RFC 3986 is stricter and more predictable.

0
ivan_morozov15 May 2026 19:55

@jnovak that error handling change is actually what pushed me toward migrating. We have several places where we get a URL from user input, pass it through parse_url(), and then silently use null values from the result because the URL was malformed. With the Uri extension those cases would throw and we would catch them properly.

0
Write a reply
Markdown. ```php blocks are runnable.