1--TEST--
2Test parse_str() function : basic functionality
3--FILE--
4<?php
5
6/* Prototype  : void parse_str  ( string $str  [, array &$arr  ] )
7 * Description: Parses the string into variables
8 * Source code: ext/standard/string.c
9*/
10
11echo "*** Testing parse_str() : basic functionality ***\n";
12
13echo "Basic test WITHOUT result arg\n";
14$s1 = "first=val1&second=val2&third=val3";
15var_dump(parse_str($s1));
16var_dump($first, $second, $third);
17
18echo "\nBasic test WITH undefined var for result arg\n";
19$s1 = "first=val1&second=val2&third=val3";
20var_dump(parse_str($s1, $res1));
21var_dump($res1);
22
23echo "\nBasic test WITH existing non-array var for result arg\n";
24$res2 =99;
25$s1 = "first=val1&second=val2&third=val3";
26var_dump(parse_str($s1, $res2));
27var_dump($res2);
28
29echo "\nBasic test with an existing array as results array\n";
30$res3_array = array(1,2,3,4);
31var_dump(parse_str($s1, $res3_array));
32var_dump($res3_array);
33
34?>
35===DONE===
36--EXPECTF--
37*** Testing parse_str() : basic functionality ***
38Basic test WITHOUT result arg
39NULL
40string(4) "val1"
41string(4) "val2"
42string(4) "val3"
43
44Basic test WITH undefined var for result arg
45NULL
46array(3) {
47  ["first"]=>
48  string(4) "val1"
49  ["second"]=>
50  string(4) "val2"
51  ["third"]=>
52  string(4) "val3"
53}
54
55Basic test WITH existing non-array var for result arg
56NULL
57array(3) {
58  ["first"]=>
59  string(4) "val1"
60  ["second"]=>
61  string(4) "val2"
62  ["third"]=>
63  string(4) "val3"
64}
65
66Basic test with an existing array as results array
67NULL
68array(3) {
69  ["first"]=>
70  string(4) "val1"
71  ["second"]=>
72  string(4) "val2"
73  ["third"]=>
74  string(4) "val3"
75}
76===DONE===