Skip to content

Commit 0afcb34

Browse files
committed
PHPC-249: empty array should be serialized as array
1 parent c162c29 commit 0afcb34

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

src/bson.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ int php_phongo_is_array_or_document(zval **val TSRMLS_DC) /* {{{ */
587587
idx++;
588588
}
589589
} else {
590-
return IS_OBJECT;
590+
return Z_TYPE_PP(val);
591591
}
592592

593593
return IS_ARRAY;

tests/bson/bson-encode-004.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object(Person)#%d (5) {
7272
["secret":protected]=>
7373
string(24) "Hannes confidential info"
7474
}
75-
Test { "0" : { "__pclass" : { "$type" : "80", "$binary" : "UGVyc29u" }, "name" : "Hannes", "age" : 42, "address" : [ { "__pclass" : { "$type" : "80", "$binary" : "QWRkcmVzcw==" }, "zip" : 94086, "country" : "USA" }, { "__pclass" : { "$type" : "80", "$binary" : "QWRkcmVzcw==" }, "zip" : 200, "country" : "Iceland" } ], "friends" : [ { "__pclass" : { "$type" : "80", "$binary" : "UGVyc29u" }, "name" : "Jeremy", "age" : 21, "address" : { }, "friends" : { } } ] } }
75+
Test { "0" : { "__pclass" : { "$type" : "80", "$binary" : "UGVyc29u" }, "name" : "Hannes", "age" : 42, "address" : [ { "__pclass" : { "$type" : "80", "$binary" : "QWRkcmVzcw==" }, "zip" : 94086, "country" : "USA" }, { "__pclass" : { "$type" : "80", "$binary" : "QWRkcmVzcw==" }, "zip" : 200, "country" : "Iceland" } ], "friends" : [ { "__pclass" : { "$type" : "80", "$binary" : "UGVyc29u" }, "name" : "Jeremy", "age" : 21, "address" : [ ], "friends" : [ ] } ] } }
7676
0 : 1f 01 00 00 03 30 00 17 01 00 00 05 5f 5f 70 63 [.....0......__pc]
7777
10 : 6c 61 73 73 00 06 00 00 00 80 50 65 72 73 6f 6e [lass......Person]
7878
20 : 02 6e 61 6d 65 00 07 00 00 00 48 61 6e 6e 65 73 [.name.....Hannes]
@@ -88,8 +88,8 @@ Test { "0" : { "__pclass" : { "$type" : "80", "$binary" : "UGVyc29u" }, "name" :
8888
C0 : 65 6e 64 73 00 58 00 00 00 03 30 00 50 00 00 00 [ends.X....0.P...]
8989
D0 : 05 5f 5f 70 63 6c 61 73 73 00 06 00 00 00 80 50 [.__pclass......P]
9090
E0 : 65 72 73 6f 6e 02 6e 61 6d 65 00 07 00 00 00 4a [erson.name.....J]
91-
F0 : 65 72 65 6d 79 00 10 61 67 65 00 15 00 00 00 03 [eremy..age......]
92-
100 : 61 64 64 72 65 73 73 00 05 00 00 00 00 03 66 72 [address.......fr]
91+
F0 : 65 72 65 6d 79 00 10 61 67 65 00 15 00 00 00 04 [eremy..age......]
92+
100 : 61 64 64 72 65 73 73 00 05 00 00 00 00 04 66 72 [address.......fr]
9393
110 : 69 65 6e 64 73 00 05 00 00 00 00 00 00 00 00 [iends..........]
9494
array(1) {
9595
[0]=>
@@ -118,16 +118,16 @@ array(1) {
118118
["friends":protected]=>
119119
array(1) {
120120
[0]=>
121-
object(Person)#%d1 (5) {
121+
object(Person)#%d (5) {
122122
["name":protected]=>
123123
string(6) "Jeremy"
124124
["age":protected]=>
125125
int(21)
126126
["address":protected]=>
127-
object(stdClass)#%d (0) {
127+
array(0) {
128128
}
129129
["friends":protected]=>
130-
object(stdClass)#%d0 (0) {
130+
array(0) {
131131
}
132132
["secret":protected]=>
133133
string(4) "none"

tests/bson/bson-encode-005.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
BSON encoding: Object Document Mapper
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$data = array(
10+
"emptyarray" => array(),
11+
"emptyclass" => new stdclass,
12+
);
13+
14+
$s = BSON\fromArray($data);
15+
echo "Test ", BSON\toJSON($s), "\n";
16+
hex_dump($s);
17+
$ret = BSON\toArray($s);
18+
var_dump($ret);
19+
?>
20+
===DONE===
21+
<?php exit(0); ?>
22+
--EXPECTF--
23+
Test { "emptyarray" : [ ], "emptyclass" : { } }
24+
0 : 27 00 00 00 04 65 6d 70 74 79 61 72 72 61 79 00 ['....emptyarray.]
25+
10 : 05 00 00 00 00 03 65 6d 70 74 79 63 6c 61 73 73 [......emptyclass]
26+
20 : 00 05 00 00 00 00 00 [.......]
27+
array(2) {
28+
["emptyarray"]=>
29+
array(0) {
30+
}
31+
["emptyclass"]=>
32+
object(stdClass)#3 (0) {
33+
}
34+
}
35+
===DONE===

tests/functional/query-sort-003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object(MongoDB\Driver\Query)#%d (6) {
3737
int(1)
3838
}
3939
["$query"]=>
40-
object(stdClass)#%d (0) {
40+
array(0) {
4141
}
4242
}
4343
["selector"]=>

tests/standalone/manager-executeInsert-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ object(Person)#%d (5) {
7575
["age":protected]=>
7676
int(21)
7777
["address":protected]=>
78-
object(stdClass)#%d (0) {
78+
array(0) {
7979
}
8080
["friends":protected]=>
81-
object(stdClass)#%d (0) {
81+
array(0) {
8282
}
8383
["secret":protected]=>
8484
string(4) "none"

0 commit comments

Comments
 (0)