Skip to content

Commit 95c4678

Browse files
committed
PHPC-1005: Use convert_to_object() to create stdClass from array
This will ensure that the array symtable is properly converted to an object proptable in PHP 7.2 (e.g. integer key 0 converts to string key "0").
1 parent 33a5ebb commit 95c4678

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

src/bson.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,14 @@ static bool php_phongo_bson_visit_document(const bson_iter_t *iter ARG_UNUSED, c
580580
case PHONGO_TYPEMAP_NATIVE_OBJECT:
581581
default:
582582
#if PHP_VERSION_ID >= 70000
583-
object_and_properties_init(&state.zchild, zend_standard_class_def, Z_ARRVAL(state.zchild));
583+
convert_to_object(&state.zchild);
584584
if (((php_phongo_bson_state *)data)->is_visiting_array) {
585585
add_next_index_zval(retval, &state.zchild);
586586
} else {
587587
ADD_ASSOC_ZVAL(retval, key, &state.zchild);
588588
}
589589
#else
590-
object_and_properties_init(state.zchild, zend_standard_class_def, Z_ARRVAL_P(state.zchild));
590+
convert_to_object(state.zchild);
591591
if (((php_phongo_bson_state *)data)->is_visiting_array) {
592592
add_next_index_zval(retval, state.zchild);
593593
} else {
@@ -664,14 +664,14 @@ static bool php_phongo_bson_visit_array(const bson_iter_t *iter ARG_UNUSED, cons
664664

665665
case PHONGO_TYPEMAP_NATIVE_OBJECT:
666666
#if PHP_VERSION_ID >= 70000
667-
object_and_properties_init(&state.zchild, zend_standard_class_def, Z_ARRVAL(state.zchild));
667+
convert_to_object(&state.zchild);
668668
if (((php_phongo_bson_state *)data)->is_visiting_array) {
669669
add_next_index_zval(retval, &state.zchild);
670670
} else {
671671
ADD_ASSOC_ZVAL(retval, key, &state.zchild);
672672
}
673673
#else
674-
object_and_properties_init(state.zchild, zend_standard_class_def, Z_ARRVAL_P(state.zchild));
674+
convert_to_object(state.zchild);
675675
if (((php_phongo_bson_state *)data)->is_visiting_array) {
676676
add_next_index_zval(retval, state.zchild);
677677
} else {
@@ -831,9 +831,9 @@ bool php_phongo_bson_to_zval_ex(const unsigned char *data, int data_len, php_pho
831831
case PHONGO_TYPEMAP_NATIVE_OBJECT:
832832
default:
833833
#if PHP_VERSION_ID >= 70000
834-
object_and_properties_init(&state->zchild, zend_standard_class_def, Z_ARRVAL(state->zchild));
834+
convert_to_object(&state->zchild);
835835
#else
836-
object_and_properties_init(state->zchild, zend_standard_class_def, Z_ARRVAL_P(state->zchild));
836+
convert_to_object(state->zchild);
837837
#endif
838838
}
839839

tests/bson/bson-encode-004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Test { "0" : { "__pclass" : { "$binary" : "UGVyc29u", "$type" : "80" }, "name" :
9494
110 : 00 04 66 72 69 65 6e 64 73 00 05 00 00 00 00 00 [..friends.......]
9595
120 : 00 00 00 [...]
9696
object(stdClass)#%d (1) {
97-
[0]=>
97+
[%r(0|"0")%r]=>
9898
object(Person)#%d (5) {
9999
["name":protected]=>
100100
string(6) "Hannes"

tests/bson/bson-toPHP-004.phpt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object(stdClass)#%d (1) {
6767
object(stdClass)#%d (1) {
6868
["x"]=>
6969
object(stdClass)#%d (1) {
70-
[0]=>
70+
[%r(0|"0")%r]=>
7171
NULL
7272
}
7373
}
@@ -93,7 +93,7 @@ object(stdClass)#%d (1) {
9393
object(stdClass)#%d (1) {
9494
["x"]=>
9595
object(stdClass)#%d (1) {
96-
[0]=>
96+
[%r(0|"0")%r]=>
9797
bool(true)
9898
}
9999
}
@@ -119,7 +119,7 @@ object(stdClass)#%d (1) {
119119
object(stdClass)#%d (1) {
120120
["x"]=>
121121
object(stdClass)#%d (1) {
122-
[0]=>
122+
[%r(0|"0")%r]=>
123123
int(1)
124124
}
125125
}
@@ -145,7 +145,7 @@ object(stdClass)#%d (1) {
145145
object(stdClass)#%d (1) {
146146
["x"]=>
147147
object(stdClass)#%d (1) {
148-
[0]=>
148+
[%r(0|"0")%r]=>
149149
float(3.14)
150150
}
151151
}
@@ -171,7 +171,7 @@ object(stdClass)#%d (1) {
171171
object(stdClass)#%d (1) {
172172
["x"]=>
173173
object(stdClass)#%d (1) {
174-
[0]=>
174+
[%r(0|"0")%r]=>
175175
string(3) "foo"
176176
}
177177
}
@@ -198,7 +198,7 @@ object(stdClass)#%d (1) {
198198
object(stdClass)#%d (1) {
199199
["x"]=>
200200
object(stdClass)#%d (1) {
201-
[0]=>
201+
[%r(0|"0")%r]=>
202202
object(stdClass)#%d (0) {
203203
}
204204
}
@@ -230,7 +230,7 @@ object(stdClass)#%d (1) {
230230
object(stdClass)#%d (1) {
231231
["x"]=>
232232
object(stdClass)#%d (1) {
233-
[0]=>
233+
[%r(0|"0")%r]=>
234234
object(stdClass)#%d (0) {
235235
}
236236
}
@@ -263,7 +263,7 @@ object(stdClass)#%d (1) {
263263
object(stdClass)#%d (1) {
264264
["x"]=>
265265
object(stdClass)#%d (1) {
266-
[0]=>
266+
[%r(0|"0")%r]=>
267267
object(MongoDB\BSON\Binary)#%d (2) {
268268
["data"]=>
269269
string(3) "foo"
@@ -302,7 +302,7 @@ object(stdClass)#%d (1) {
302302
object(stdClass)#%d (1) {
303303
["x"]=>
304304
object(stdClass)#%d (1) {
305-
[0]=>
305+
[%r(0|"0")%r]=>
306306
object(MongoDB\BSON\Decimal128)#%d (1) {
307307
["dec"]=>
308308
string(4) "3.14"
@@ -339,7 +339,7 @@ object(stdClass)#%d (1) {
339339
object(stdClass)#%d (1) {
340340
["x"]=>
341341
object(stdClass)#%d (1) {
342-
[0]=>
342+
[%r(0|"0")%r]=>
343343
object(MongoDB\BSON\Javascript)#%d (2) {
344344
["code"]=>
345345
string(12) "function(){}"
@@ -376,7 +376,7 @@ object(stdClass)#%d (1) {
376376
object(stdClass)#%d (1) {
377377
["x"]=>
378378
object(stdClass)#%d (1) {
379-
[0]=>
379+
[%r(0|"0")%r]=>
380380
object(MongoDB\BSON\MaxKey)#%d (0) {
381381
}
382382
}
@@ -405,7 +405,7 @@ object(stdClass)#%d (1) {
405405
object(stdClass)#%d (1) {
406406
["x"]=>
407407
object(stdClass)#%d (1) {
408-
[0]=>
408+
[%r(0|"0")%r]=>
409409
object(MongoDB\BSON\MinKey)#%d (0) {
410410
}
411411
}
@@ -436,7 +436,7 @@ object(stdClass)#%d (1) {
436436
object(stdClass)#%d (1) {
437437
["x"]=>
438438
object(stdClass)#%d (1) {
439-
[0]=>
439+
[%r(0|"0")%r]=>
440440
object(MongoDB\BSON\ObjectId)#%d (1) {
441441
["oid"]=>
442442
string(24) "586c18d86118fd6c9012dec1"
@@ -473,7 +473,7 @@ object(stdClass)#%d (1) {
473473
object(stdClass)#%d (1) {
474474
["x"]=>
475475
object(stdClass)#%d (1) {
476-
[0]=>
476+
[%r(0|"0")%r]=>
477477
object(MongoDB\BSON\Regex)#%d (2) {
478478
["pattern"]=>
479479
string(3) "foo"
@@ -514,7 +514,7 @@ object(stdClass)#%d (1) {
514514
object(stdClass)#%d (1) {
515515
["x"]=>
516516
object(stdClass)#%d (1) {
517-
[0]=>
517+
[%r(0|"0")%r]=>
518518
object(MongoDB\BSON\Timestamp)#%d (2) {
519519
["increment"]=>
520520
string(4) "1234"
@@ -553,7 +553,7 @@ object(stdClass)#%d (1) {
553553
object(stdClass)#%d (1) {
554554
["x"]=>
555555
object(stdClass)#%d (1) {
556-
[0]=>
556+
[%r(0|"0")%r]=>
557557
object(MongoDB\BSON\UTCDateTime)#%d (1) {
558558
["milliseconds"]=>
559559
string(13) "1483479256924"

tests/bson/bug0974-001.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ object(stdClass)#%d (%d) {
3131
}
3232
}
3333
object(stdClass)#%d (%d) {
34-
[0]=>
34+
[%r(0|"0")%r]=>
3535
int(1)
36-
[1]=>
36+
[%r(1|"1")%r]=>
3737
int(2)
38-
[2]=>
38+
[%r(2|"2")%r]=>
3939
int(3)
40-
[3]=>
40+
[%r(3|"3")%r]=>
4141
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
4242
["milliseconds"]=>
4343
string(13) "1497352886906"
4444
}
4545
}
4646
object(stdClass)#3 (2) {
47-
[0]=>
47+
[%r(0|"0")%r]=>
4848
object(MongoDB\BSON\ObjectId)#%d (%d) {
4949
["oid"]=>
5050
string(24) "55f2b3f1f657b3fa97c9c0a2"
5151
}
52-
[1]=>
52+
[%r(1|"1")%r]=>
5353
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
5454
["milliseconds"]=>
5555
string(13) "1497352886906"

tests/functional/query-sort-004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ object(MongoDB\Driver\Query)#%d (%d) {
4848
object(stdClass)#%d (%d) {
4949
["sort"]=>
5050
object(stdClass)#%d (%d) {
51-
[0]=>
51+
[%r(0|"0")%r]=>
5252
int(1)
5353
}
5454
}

0 commit comments

Comments
 (0)