parse_url() has been the Swiss Army knife of "please split this string" for a long time. It still works. It also still admits, in the manual, that it does not follow an established URI or URL standard.
That sentence is the whole story. If you build booking links, redirects, webhooks or allow-lists for small business sites, "best effort" parsing is not a feature. It is a footgun with good intentions.
PHP 8.5 ships a built-in URI extension that implements the RFC 3986 and WHATWG URL specifications. The PHP 8.5 release notes put it front and centre for a reason.
What parse_url() actually promises
The parse_url() manual page is blunt:
- it is not meant to validate a URL
- it does not follow any established URI or URL standard
- it can return incorrect or nonsense results for relative or malformed URLs
- even for valid URLs, results may differ from another parser
It then spells out the security angle. Validating a hostname with parser A, then fetching with parser B that reads the host differently, is a classic way to lose an allow-list fight.
The same page strongly recommends Uri\Rfc3986\Uri and Uri\WhatWg\Url for newly written code, and migrating existing parse_url() uses unless you must keep the old behaviour for compatibility.
That is not marketing copy. That is the documentation telling you to stop treating parse_url() as a standards engine.
What the URI extension gives you
Per the URI book and the class synopsis for Uri\Rfc3986\Uri:
- the extension follows RFC 3986 and the WHATWG URL specs
Uri\Rfc3986\Uriis a final readonly class- construct with
new Uri\Rfc3986\Uri(string $uri, ?Uri\Rfc3986\Uri $baseUrl = null) - getters include
getHost(),getPath(),getQuery(), plusgetRaw*variants when you need the un-normalised form equals()compares two URIsUri\WhatWg\Urlcovers the browser-shaped WHATWG model
The release page's shape is the everyday one: build a URI object, then ask for the component you care about instead of indexing an associative array and hoping the key exists.
Example from the PHP 8.5 release notes:
``` use Uri\Rfc3986\Uri;
$uri = new Uri('https://php.net/releases/8.5/en.php');
var_dump($uri->getHost()); // string(7) "php.net" ```
Same idea as parse_url(..., PHP_URL_HOST), except the object is bound to a named standard.
When to migrate — and when to leave it alone
Migrate when:
- you accept redirects, callbacks or user-supplied URLs
- you compare hosts for allow-lists or soft redirects
- you resolve relative links against a base URL
- you are writing new code on PHP 8.5+
Keep parse_url() only when you must preserve its exact historical quirks for compatibility. The manual says that out loud. Compatibility is a reason. Habit is not.
For small business PHP — booking confirmations, invoice links, catalogue filters that accept a return URL — prefer the class that names the standard you think you are using. RFC 3986 for classical URI rules. WHATWG when you need browser URL behaviour. Guessing is how two parsers disagree about the same string.
Fit with the rest of a tidy PHP 8.5 codebase
URI handling sits beside the other PHP 8.5 habits that shrink accidental complexity: pipe operator chains where a transform is obvious, clone with for readonly value objects where immutability matters, and an honest runtime check if you are still on older PHP — see PHP 8.2 end-of-life.
Keep declare(strict_types=1); at the top of new files. A standards-based URI class does not replace types at the method boundary.
Where to go next
Readonly objects, enums, match, strict types and tested examples run through PHP Done The Correct Way. The companion code page has the downloads, and the book page has the details.
If the next person to touch your redirects should not need a detective novel to know which parser you meant, start with the URI extension.
Need help putting PHP 8.5 habits into a small business codebase? See PHP AIR services.