Uri\WhatWg\Url::withPort
PHP Manual
PHP Manual»Uri\WhatWg\Url»Uri\WhatWg\Url::withPort

Uri\WhatWg\Url::withPort

(PHP 8 >= 8.5.0)

Uri\WhatWg\Url::withPort — Modifie le composant port

Description

public function Uri\WhatWg\Url::withPort(?int $port): static

Crée une nouvelle URL et modifie son composant port.

Liste de paramètres

port

Nouveau composant port.

Valeurs de retour

L'instance Uri\WhatWg\Url modifiée.

Erreurs / Exceptions

Si l'URL résultante est invalide, une exception Uri\WhatWg\InvalidUrlException est lancée.

Exemples

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)

Voir aussi

To Top