[DOC-CVS] [doc-en] master: fix(reference/stream): example code php5.4 array syntax

[email protected] ("Hans Krentel (hakre) via Niels Dossche")
Newsgroups php.doc.cvs
Message-ID <[email protected]>
Author: Hans Krentel (hakre) (hakre)
Committer: Niels Dossche (nielsdos)
Date: 2025-06-22T16:45:06+02:00

Commit: https://github.com/php/doc-en/commit/3abd17e61d5022d503604cc06894254e3281acf5
Raw diff: https://github.com/php/doc-en/commit/3abd17e61d5022d503604cc06894254e3281acf5.diff

fix(reference/stream): example code php5.4 array syntax

in reference to 037266adde ("fix(reference/stream): HTTP headers are U+0D U+0A (CR LF) separated", 2025-06-22) streamline by 'http' 'header' stream context option.

Changed paths:
  M  language/context/http.xml
  M  reference/filesystem/functions/file-get-contents.xml
  M  reference/libxml/functions/libxml-set-streams-context.xml
  M  reference/stream/functions/stream-context-get-default.xml
  M  reference/stream/functions/stream-context-set-default.xml
  M  reference/xmlrpc/functions/xmlrpc-encode-request.xml


Diff:

diff --git a/language/context/http.xml b/language/context/http.xml
index 2023f378b7f0..f11e1097bca8 100644
--- a/language/context/http.xml
+++ b/language/context/http.xml
@@ -208,19 +208,19 @@
 <?php
 
 $postdata = http_build_query(
-    array(
+    [
         'var1' => 'some content',
-        'var2' => 'doh'
-    )
+        'var2' => 'doh',
+    ]
 );
 
-$opts = array('http' =>
-    array(
+$opts = [
+    'http' => [
         'method'  => 'POST',
         'header'  => 'Content-type: application/x-www-form-urlencoded',
-        'content' => $postdata
-    )
-);
+        'content' => $postdata,
+    ]
+];
 
 $context = stream_context_create($opts);
 
@@ -240,13 +240,13 @@ $result = file_get_contents('http://example.com/submit.php', false, $context);
 
 $url = "http://www.example.org/header.php";
 
-$opts = array('http' =>
-    array(
-        'method' => 'GET',
+$opts = [
+    'http' => [
+        'method'        => 'GET',
         'max_redirects' => '0',
-        'ignore_errors' => '1'
-    )
-);
+        'ignore_errors' => '1',
+    ]
+];
 
 $context = stream_context_create($opts);
 $stream = fopen($url, 'r', false, $context);
diff --git a/reference/filesystem/functions/file-get-contents.xml b/reference/filesystem/functions/file-get-contents.xml
index 346b2c625c48..624b1a3e8bde 100644
--- a/reference/filesystem/functions/file-get-contents.xml
+++ b/reference/filesystem/functions/file-get-contents.xml
@@ -204,13 +204,13 @@ string(14) "lle Bjori Ro"
 <![CDATA[
 <?php
 // Create a stream
-$opts = array(
-  'http'=>array(
-    'method'=>"GET",
-    'header'=>"Accept-language: en\r\n" .
-              "Cookie: foo=bar\r\n"
-  )
-);
+$opts = [
+  'http' => [
+    'method' => "GET",
+    'header' => "Accept-language: en\r\n" .
+                "Cookie: foo=bar",
+  ]
+];
 
 $context = stream_context_create($opts);
 
diff --git a/reference/libxml/functions/libxml-set-streams-context.xml b/reference/libxml/functions/libxml-set-streams-context.xml
index de172da1580d..737c206f03d2 100644
--- a/reference/libxml/functions/libxml-set-streams-context.xml
+++ b/reference/libxml/functions/libxml-set-streams-context.xml
@@ -83,11 +83,11 @@
     <programlisting role="php" annotations="non-interactive">
 <![CDATA[
 <?php
-$opts = array(
-    'http' => array(
+$opts = [
+    'http' => [
         'user_agent' => 'PHP libxml agent',
-    )
-);
+    ]
+];
 
 $context = stream_context_create($opts);
 libxml_set_streams_context($context);
diff --git a/reference/stream/functions/stream-context-get-default.xml b/reference/stream/functions/stream-context-get-default.xml
index 91c5b6ff87ed..e637434fad54 100644
--- a/reference/stream/functions/stream-context-get-default.xml
+++ b/reference/stream/functions/stream-context-get-default.xml
@@ -76,24 +76,24 @@
     <programlisting role="php">
 <![CDATA[
 <?php
-$default_opts = array(
-  'http'=>array(
-    'method'=>"GET",
-    'header'=>"Accept-language: en\r\n" .
-              "Cookie: foo=bar",
-    'proxy'=>"tcp://10.54.1.39:8000"
-  )
-);
+$default_opts = [
+  'http' => [
+    'method' => "GET",
+    'header' => "Accept-language: en\r\n" .
+                "Cookie: foo=bar",
+    'proxy' =>  "tcp://10.54.1.39:8000",
+  ]
+];
 
 
-$alternate_opts = array(
-  'http'=>array(
-    'method'=>"POST",
-    'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .
-              "Content-length: " . strlen("baz=bomb"),
-    'content'=>"baz=bomb"
-  )
-);
+$alternate_opts = [
+  'http' => [
+    'method'  => "POST",
+    'header'  => "Content-type: application/x-www-form-urlencoded\r\n" .
+                 "Content-length: " . strlen("baz=bomb"),
+    'content' => "baz=bomb",
+  ]
+];
 
 $default = stream_context_get_default($default_opts);
 $alternate = stream_context_create($alternate_opts);
diff --git a/reference/stream/functions/stream-context-set-default.xml b/reference/stream/functions/stream-context-set-default.xml
index dfcd36573907..08dfe1bd3fd0 100644
--- a/reference/stream/functions/stream-context-set-default.xml
+++ b/reference/stream/functions/stream-context-set-default.xml
@@ -58,14 +58,14 @@
     <programlisting role="php">
 <![CDATA[
 <?php
-$default_opts = array(
-  'http'=>array(
-    'method'=>"GET",
-    'header'=>"Accept-language: en\r\n" .
-              "Cookie: foo=bar",
-    'proxy'=>"tcp://10.54.1.39:8000"
-  )
-);
+$default_opts = [
+  'http' => [
+    'method' => "GET",
+    'header' => "Accept-language: en\r\n" .
+                "Cookie: foo=bar",
+    'proxy'  => "tcp://10.54.1.39:8000",
+  ]
+];
 
 $default = stream_context_set_default($default_opts);
 
diff --git a/reference/xmlrpc/functions/xmlrpc-encode-request.xml b/reference/xmlrpc/functions/xmlrpc-encode-request.xml
index 9b2dd0e5b38f..751079d066ee 100644
--- a/reference/xmlrpc/functions/xmlrpc-encode-request.xml
+++ b/reference/xmlrpc/functions/xmlrpc-encode-request.xml
@@ -72,12 +72,14 @@
     <programlisting role="php">
 <![CDATA[
 <?php
-$request = xmlrpc_encode_request("method", array(1, 2, 3));
-$context = stream_context_create(array('http' => array(
-    'method' => "POST",
-    'header' => "Content-Type: text/xml",
-    'content' => $request
-)));
+$request = xmlrpc_encode_request("method", [1, 2, 3]);
+$context = stream_context_create([
+    'http' => [
+        'method'  => "POST",
+        'header'  => "Content-Type: text/xml",
+        'content' => $request,
+    ]
+]);
 $file = file_get_contents("http://www.example.com/xmlrpc", false, $context);
 $response = xmlrpc_decode($file);
 if ($response && xmlrpc_is_fault($response)) {
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.