(PHP 8 >= 8.5.0)
Uri\WhatWg\Url::withPort — Modifie le composant port
Crée une nouvelle URL et modifie son composant port.
portNouveau composant port.
L'instance Uri\WhatWg\Url modifiée.
Si l'URL résultante est invalide, une exception Uri\WhatWg\InvalidUrlException est lancée.
Exemple #1 Exemple simple avec Uri\WhatWg\Url::withPort()
<?php
$url = new \Uri\WhatWg\Url("https://example.com:8080");
// 443 est le port par défaut pour https, il n'est donc pas conservé.
$url = $url->withPort(443);
var_dump($url->getPort());
$url = $url->withPort(8443);
var_dump($url->getPort());
?>L'exemple ci-dessus va afficher :
NULL int(8443)