Skip to content

Commit 6bfea28

Browse files
committed
Merge branch 'PHP-5.4'
* PHP-5.4: Fixing up closing tag Testing variation on input parameters of http_build_query() function
2 parents bbb5eba + 8b70dd2 commit 6bfea28

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Test http_build_query() function: usage variations - first arguments as object
3+
--CREDITS--
4+
Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
5+
--FILE--
6+
<?php
7+
/* Prototype : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
8+
* Description: Generates a URL-encoded query string from the associative (or indexed) array provided.
9+
* Source code: ext/standard/http.c
10+
*/
11+
12+
class UrlBuilder
13+
{
14+
public $name = 'homepage';
15+
public $page = 1;
16+
protected $sort = 'desc,name';
17+
private $access = 'admin';
18+
}
19+
20+
$obj = new stdClass;
21+
$obj->name = 'homepage';
22+
$obj->page = 1;
23+
$obj->sort = 'desc,name';
24+
25+
echo http_build_query($obj) . PHP_EOL;
26+
echo http_build_query(new UrlBuilder());
27+
?>
28+
--EXPECTF--
29+
name=homepage&page=1&sort=desc%2Cname
30+
name=homepage&page=1
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
Test http_build_query() function: usage variations - first arguments as multidimensional array and second argument present/not present
3+
--CREDITS--
4+
Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
5+
--FILE--
6+
<?php
7+
/* Prototype : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
8+
* Description: Generates a URL-encoded query string from the associative (or indexed) array provided.
9+
* Source code: ext/standard/http.c
10+
*/
11+
12+
$mDimensional = array(
13+
20,
14+
5 => 13,
15+
"9" => array(
16+
1 => "val1",
17+
3 => "val2",
18+
"string" => "string"
19+
),
20+
"name" => "homepage",
21+
"page" => 10,
22+
"sort" => array(
23+
"desc",
24+
"admin" => array(
25+
"admin1",
26+
"admin2" => array(
27+
"who" => "admin2",
28+
2 => "test"
29+
)
30+
)
31+
)
32+
);
33+
34+
echo http_build_query($mDimensional) . PHP_EOL;
35+
echo http_build_query($mDimensional, 'prefix_');
36+
?>
37+
--EXPECTF--
38+
0=20&5=13&9%5B1%5D=val1&9%5B3%5D=val2&9%5Bstring%5D=string&name=homepage&page=10&sort%5B0%5D=desc&sort%5Badmin%5D%5B0%5D=admin1&sort%5Badmin%5D%5Badmin2%5D%5Bwho%5D=admin2&sort%5Badmin%5D%5Badmin2%5D%5B2%5D=test
39+
prefix_0=20&prefix_5=13&prefix_9%5B1%5D=val1&prefix_9%5B3%5D=val2&prefix_9%5Bstring%5D=string&name=homepage&page=10&sort%5B0%5D=desc&sort%5Badmin%5D%5B0%5D=admin1&sort%5Badmin%5D%5Badmin2%5D%5Bwho%5D=admin2&sort%5Badmin%5D%5Badmin2%5D%5B2%5D=test
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Test http_build_query() function: usage variations - testing four parameter added in PHP 5.4.0
3+
--CREDITS--
4+
Adam Gegotek <adam [dot] gegotek [at] gmail [dot] com>
5+
--SKIPIF--
6+
<?php
7+
if (version_compare(PHP_VERSION, '5.4.0', '<')) die("skip this test if PHP_VERSION is less than 5.4.0");
8+
?>
9+
--FILE--
10+
<?php
11+
/* Prototype : string http_build_query ( mixed $query_data [, string $numeric_prefix [, string $arg_separator [, int $enc_type = PHP_QUERY_RFC1738 ]]] )
12+
* Description: Generates a URL-encoded query string from the associative (or indexed) array provided.
13+
* Source code: ext/standard/http.c
14+
*/
15+
16+
$oDimensional = array(
17+
"name" => "main page",
18+
"sort" => "desc,admin",
19+
"equation" => "10 + 10 - 5"
20+
);
21+
22+
echo http_build_query($oDimensional, '', ini_get('arg_separator.output'), PHP_QUERY_RFC1738) . PHP_EOL;
23+
echo http_build_query($oDimensional, '', ini_get('arg_separator.output'), PHP_QUERY_RFC3986);
24+
?>
25+
--EXPECTF--
26+
name=main+page&sort=desc%2Cadmin&equation=10+%2B+10+-+5
27+
name=main%20page&sort=desc%2Cadmin&equation=10%20%2B%2010%20-%205

0 commit comments

Comments
 (0)