Uri\WhatWg\Url::withPort
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.5.0)
Modify the port component
Description
Uri\WhatWg\Url::withPort(int|null $port): static
Creates a new URL and modifies its port component.
Parameters
portNew port component.
Return Values
The modified Uri\WhatWg\Url instance.
Errors/Exceptions InvalidUrlException
Examples
Uri\WhatWg\Url::withPort basic example
php
<?php
$url = new \Uri\WhatWg\Url("https://example.com:8080");
// 443 is the default port for https, so it is not stored.
$url = $url->withPort(443);
var_dump($url->getPort());
$url = $url->withPort(8443);
var_dump($url->getPort());
?>The above example will output:
output
NULL
int(8443)See Also
Uri\WhatWg\Url::getPortUri\Rfc3986\Uri::withPort