Post #4481692
2026-08-10 07:36 UTC
So... PHP and Javascript comparison....
Parsing a URL:
PHP:
var_Dump(parse_url('example.com:80'));
array(2) {
["host"]=>
string(11) "example.com"
["port"]=>
int(80)
}
JavaScript:
a = new URL('example.com:80');
URL {
href: "example.com:80",
origin: "null",
protocol: "example.com:",
username: "",
password: "",
host: "",
hostname: "",
port: "",
pathname: "80",
search: ""
}
I know which side *I* stick with....
#PHP #JavaScript
Replies (2)
-
@heiglandreas@phpc.social 2026-08-10 07:37
And 🤫 JS: a = new URL('example.com'); Uncaught TypeError: URL constructor: example.com is not a valid URL. Technically that might be correct, but a = new URL('example.com:'); URL { href: "example.com:", origin: "null", protocol: "example.com:", username: "", password: "", host: "", hostname: "", port: "", pathname: "", search: "" } 🤯
-
@CFDS@vis.social 2026-08-10 08:10
@heiglandreas@phpc.social Sticking with the side which takes a wild guess, instead of following URL specification? 😏 "example.com:80" is a valid but *malformed* URL, because an URL must always begin with the scheme.