Skip to content

Commit 3abd17e

Browse files
hakrenielsdos
authored andcommitted
fix(reference/stream): example code php5.4 array syntax
in reference to 037266a ("fix(reference/stream): HTTP headers are U+0D U+0A (CR LF) separated", 2025-06-22) streamline by 'http' 'header' stream context option.
1 parent c49274b commit 3abd17e

File tree

6 files changed

+57
-55
lines changed

6 files changed

+57
-55
lines changed

language/context/http.xml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,19 @@
208208
<?php
209209
210210
$postdata = http_build_query(
211-
array(
211+
[
212212
'var1' => 'some content',
213-
'var2' => 'doh'
214-
)
213+
'var2' => 'doh',
214+
]
215215
);
216216
217-
$opts = array('http' =>
218-
array(
217+
$opts = [
218+
'http' => [
219219
'method' => 'POST',
220220
'header' => 'Content-type: application/x-www-form-urlencoded',
221-
'content' => $postdata
222-
)
223-
);
221+
'content' => $postdata,
222+
]
223+
];
224224
225225
$context = stream_context_create($opts);
226226
@@ -240,13 +240,13 @@ $result = file_get_contents('http://example.com/submit.php', false, $context);
240240
241241
$url = "http://www.example.org/header.php";
242242
243-
$opts = array('http' =>
244-
array(
245-
'method' => 'GET',
243+
$opts = [
244+
'http' => [
245+
'method' => 'GET',
246246
'max_redirects' => '0',
247-
'ignore_errors' => '1'
248-
)
249-
);
247+
'ignore_errors' => '1',
248+
]
249+
];
250250
251251
$context = stream_context_create($opts);
252252
$stream = fopen($url, 'r', false, $context);

reference/filesystem/functions/file-get-contents.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,13 @@ string(14) "lle Bjori Ro"
204204
<![CDATA[
205205
<?php
206206
// Create a stream
207-
$opts = array(
208-
'http'=>array(
209-
'method'=>"GET",
210-
'header'=>"Accept-language: en\r\n" .
211-
"Cookie: foo=bar\r\n"
212-
)
213-
);
207+
$opts = [
208+
'http' => [
209+
'method' => "GET",
210+
'header' => "Accept-language: en\r\n" .
211+
"Cookie: foo=bar",
212+
]
213+
];
214214
215215
$context = stream_context_create($opts);
216216

reference/libxml/functions/libxml-set-streams-context.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@
8383
<programlisting role="php" annotations="non-interactive">
8484
<![CDATA[
8585
<?php
86-
$opts = array(
87-
'http' => array(
86+
$opts = [
87+
'http' => [
8888
'user_agent' => 'PHP libxml agent',
89-
)
90-
);
89+
]
90+
];
9191
9292
$context = stream_context_create($opts);
9393
libxml_set_streams_context($context);

reference/stream/functions/stream-context-get-default.xml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,24 @@
7676
<programlisting role="php">
7777
<![CDATA[
7878
<?php
79-
$default_opts = array(
80-
'http'=>array(
81-
'method'=>"GET",
82-
'header'=>"Accept-language: en\r\n" .
83-
"Cookie: foo=bar",
84-
'proxy'=>"tcp://10.54.1.39:8000"
85-
)
86-
);
79+
$default_opts = [
80+
'http' => [
81+
'method' => "GET",
82+
'header' => "Accept-language: en\r\n" .
83+
"Cookie: foo=bar",
84+
'proxy' => "tcp://10.54.1.39:8000",
85+
]
86+
];
8787
8888
89-
$alternate_opts = array(
90-
'http'=>array(
91-
'method'=>"POST",
92-
'header'=>"Content-type: application/x-www-form-urlencoded\r\n" .
93-
"Content-length: " . strlen("baz=bomb"),
94-
'content'=>"baz=bomb"
95-
)
96-
);
89+
$alternate_opts = [
90+
'http' => [
91+
'method' => "POST",
92+
'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
93+
"Content-length: " . strlen("baz=bomb"),
94+
'content' => "baz=bomb",
95+
]
96+
];
9797
9898
$default = stream_context_get_default($default_opts);
9999
$alternate = stream_context_create($alternate_opts);

reference/stream/functions/stream-context-set-default.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
<programlisting role="php">
5959
<![CDATA[
6060
<?php
61-
$default_opts = array(
62-
'http'=>array(
63-
'method'=>"GET",
64-
'header'=>"Accept-language: en\r\n" .
65-
"Cookie: foo=bar",
66-
'proxy'=>"tcp://10.54.1.39:8000"
67-
)
68-
);
61+
$default_opts = [
62+
'http' => [
63+
'method' => "GET",
64+
'header' => "Accept-language: en\r\n" .
65+
"Cookie: foo=bar",
66+
'proxy' => "tcp://10.54.1.39:8000",
67+
]
68+
];
6969
7070
$default = stream_context_set_default($default_opts);
7171

reference/xmlrpc/functions/xmlrpc-encode-request.xml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@
7272
<programlisting role="php">
7373
<![CDATA[
7474
<?php
75-
$request = xmlrpc_encode_request("method", array(1, 2, 3));
76-
$context = stream_context_create(array('http' => array(
77-
'method' => "POST",
78-
'header' => "Content-Type: text/xml",
79-
'content' => $request
80-
)));
75+
$request = xmlrpc_encode_request("method", [1, 2, 3]);
76+
$context = stream_context_create([
77+
'http' => [
78+
'method' => "POST",
79+
'header' => "Content-Type: text/xml",
80+
'content' => $request,
81+
]
82+
]);
8183
$file = file_get_contents("http://www.example.com/xmlrpc", false, $context);
8284
$response = xmlrpc_decode($file);
8385
if ($response && xmlrpc_is_fault($response)) {

0 commit comments

Comments
 (0)