[DOC-CVS] [doc-en] master: Fix Uri\WhatWg\Url screens that ignore URL normalization (#5721)

[email protected] (KentarouTakeda via GitHub)
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: KentarouTakeda (KentarouTakeda)
Committer: GitHub (web-flow)
Pusher: jordikroon
Date: 2026-08-07T11:06:45+02:00

Commit: https://github.com/php/doc-en/commit/0e06411471a898974e114bd57f624781fe3a0b89
Raw diff: https://github.com/php/doc-en/commit/0e06411471a898974e114bd57f624781fe3a0b89.diff

Fix Uri\WhatWg\Url screens that ignore URL normalization (#5721)

A WHATWG URL does not store the port when it is the scheme's default, so
getPort() and withPort() both echoed null while their screens claimed
443, and Url::parse() normalizes an empty path to "/", which its screen
did not show. The extension is new in PHP 8.5, so these were wrong from
the start.

Echoing null renders as an empty box, so the two port examples use
var_dump() now and also show a port that is kept: the contrast is what
makes the normalization legible.

Changed paths:
  M  reference/uri/uri/whatwg/url/getport.xml
  M  reference/uri/uri/whatwg/url/parse.xml
  M  reference/uri/uri/whatwg/url/withport.xml


Diff:

diff --git a/reference/uri/uri/whatwg/url/getport.xml b/reference/uri/uri/whatwg/url/getport.xml
index 10587042db8e..c123438c6158 100644
--- a/reference/uri/uri/whatwg/url/getport.xml
+++ b/reference/uri/uri/whatwg/url/getport.xml
@@ -35,16 +35,20 @@
    <programlisting role="php">
 <![CDATA[
 <?php
-$url = new \Uri\WhatWg\Url("https://example.com:443");
+$url = new \Uri\WhatWg\Url("https://example.com:8080");
+var_dump($url->getPort());
 
-echo $url->getPort();
+// 443 is the default port for https, so it is not stored.
+$url = new \Uri\WhatWg\Url("https://example.com:443");
+var_dump($url->getPort());
 ?>
 ]]>
    </programlisting>
    &example.outputs;
    <screen>
 <![CDATA[
-443
+int(8080)
+NULL
 ]]>
    </screen>
   </example>
diff --git a/reference/uri/uri/whatwg/url/parse.xml b/reference/uri/uri/whatwg/url/parse.xml
index 560af29fd6e0..a14cb5ebf7a8 100644
--- a/reference/uri/uri/whatwg/url/parse.xml
+++ b/reference/uri/uri/whatwg/url/parse.xml
@@ -79,7 +79,7 @@ if ($url !== null) {
    &example.outputs;
    <screen>
 <![CDATA[
-Valid URL: https://example.com
+Valid URL: https://example.com/
 ]]>
    </screen>
   </example>
diff --git a/reference/uri/uri/whatwg/url/withport.xml b/reference/uri/uri/whatwg/url/withport.xml
index 400eabac1e06..ec298021a044 100644
--- a/reference/uri/uri/whatwg/url/withport.xml
+++ b/reference/uri/uri/whatwg/url/withport.xml
@@ -50,16 +50,21 @@
 <![CDATA[
 <?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());
 
-echo $url->getPort();
+$url = $url->withPort(8443);
+var_dump($url->getPort());
 ?>
 ]]>
    </programlisting>
    &example.outputs;
    <screen>
 <![CDATA[
-443
+NULL
+int(8443)
 ]]>
    </screen>
   </example>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.