Skip to content

Commit 4a96c4b

Browse files
Girgiasnielsdos
authored andcommitted
Add more tests with objects
1 parent 4ef865e commit 4a96c4b

8 files changed

+108
-17
lines changed

ext/standard/tests/http/http_build_query/bug26817.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ $obj->foo();
2222
var_dump(http_build_query($obj));
2323
?>
2424
--EXPECT--
25-
string(27) "foo=lala&bar=meuh&test=test"
25+
string(27) "test=test&bar=meuh&foo=lala"
2626
string(9) "test=test"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
http_build_query() function with object
3+
--FILE--
4+
<?php
5+
class KeyVal {
6+
public $public = "input";
7+
protected $protected = "hello";
8+
private $private = "world";
9+
}
10+
11+
$o = new KeyVal();
12+
13+
// Percent encoded "public=input"
14+
var_dump(http_build_query($o));
15+
?>
16+
--EXPECT--
17+
string(12) "public=input"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
http_build_query() function with empty object
3+
--FILE--
4+
<?php
5+
class EmptyObj {}
6+
$o = new EmptyObj();
7+
8+
var_dump(http_build_query($o));
9+
?>
10+
--EXPECT--
11+
string(0) ""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
http_build_query() function with object that is just stringable (GH-10229)
3+
--FILE--
4+
<?php
5+
class StringableObject {
6+
public function __toString() : string {
7+
return "Stringable";
8+
}
9+
}
10+
11+
$o = new StringableObject();
12+
13+
var_dump(http_build_query(['hello', $o]));
14+
var_dump(http_build_query($o));
15+
var_dump(http_build_query(['hello', $o], numeric_prefix: 'prefix_'));
16+
var_dump(http_build_query($o, numeric_prefix: 'prefix_'));
17+
?>
18+
--EXPECT--
19+
string(20) "0=hello&1=Stringable"
20+
string(12) "0=Stringable"
21+
string(34) "prefix_0=hello&prefix_1=Stringable"
22+
string(19) "prefix_0=Stringable"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
http_build_query() function with recursif object
3+
--FILE--
4+
<?php
5+
class KeyValStringable {
6+
public $public = "input";
7+
protected $protected = "hello";
8+
private $private = "world";
9+
10+
public function __toString(): string {
11+
return "Stringable";
12+
}
13+
}
14+
15+
$o = new KeyValStringable();
16+
17+
var_dump(http_build_query($o));
18+
?>
19+
--EXPECT--
20+
string(12) "public=input"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
http_build_query() function with nested object
3+
--FILE--
4+
<?php
5+
class KeyVal {
6+
public $public = "input";
7+
protected $protected = "hello";
8+
private $private = "world";
9+
}
10+
11+
$o = new KeyVal();
12+
$nested = new KeyVal();
13+
14+
$o->public = $nested;
15+
16+
// Percent encoded "public[public]=input"
17+
var_dump(http_build_query($o));
18+
?>
19+
--EXPECT--
20+
string(24) "public%5Bpublic%5D=input"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
http_build_query() function with recursif object
3+
--FILE--
4+
<?php
5+
class KeyVal {
6+
public $public = "input";
7+
protected $protected = "hello";
8+
private $private = "world";
9+
}
10+
11+
$o = new KeyVal();
12+
$o->public = $o;
13+
14+
var_dump(http_build_query($o));
15+
?>
16+
--EXPECT--
17+
string(0) ""

ext/standard/tests/http/http_build_query/http_build_query_with_stringable_object.phpt

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)