1
+ --TEST--
2
+ PHPC-2505: gc_collect_cycles() may interfere with using foreach to iterate objects
3
+ --FILE--
4
+ <?php
5
+ require_once __DIR__ . "/../utils/basic.inc " ;
6
+
7
+ $ tests = [
8
+ [ 'binary ' => new MongoDB \BSON \Binary ('foo ' , MongoDB \BSON \Binary::TYPE_GENERIC ) ],
9
+ [ 'dbpointer ' => createDBPointer () ],
10
+ [ 'decimal128 ' => new MongoDB \BSON \Decimal128 ('1234.5678 ' ) ],
11
+ [ 'int64 ' => new MongoDB \BSON \Int64 ('9223372036854775807 ' ) ],
12
+ // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway
13
+ [ 'javascript ' => new MongoDB \BSON \Javascript ('function() { return 1; } ' ) ],
14
+ [ 'javascript_ws ' => new MongoDB \BSON \Javascript ('function() { return a; } ' , ['a ' => 1 ]) ],
15
+ // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway
16
+ [ 'maxkey ' => new MongoDB \BSON \MaxKey ],
17
+ [ 'minkey ' => new MongoDB \BSON \MinKey ],
18
+ [ 'objectid ' => new MongoDB \BSON \ObjectId ],
19
+ [ 'regex ' => new MongoDB \BSON \Regex ('pattern ' , 'i ' ) ],
20
+ [ 'symbol ' => createSymbol () ],
21
+ [ 'timestamp ' => new MongoDB \BSON \Timestamp (1234 , 5678 ) ],
22
+ [ 'utcdatetime ' => new MongoDB \BSON \UTCDateTime ],
23
+ ];
24
+
25
+ ob_start ();
26
+ foreach ($ tests as $ test ) {
27
+ echo key ($ test ), "\n" ;
28
+
29
+ foreach ($ test as $ k => $ v ) {
30
+ var_dump ($ k , $ v );
31
+ }
32
+ }
33
+ $ buf1 = ob_end_clean ();
34
+
35
+ ob_start ();
36
+ foreach ($ tests as $ test ) {
37
+ echo key ($ test ), "\n" ;
38
+
39
+ foreach ($ test as $ k => $ v ) {
40
+ var_dump ($ k , $ v );
41
+ }
42
+ }
43
+ $ buf2 = ob_end_clean ();
44
+
45
+ if ($ buf1 === $ buf2 ) {
46
+ echo "OK! \n" ;
47
+ exit (0 );
48
+ } else {
49
+ echo ("buf1 != buf2: $ buf1 \n!= \n$ buf2 \n" );
50
+ }
51
+
52
+ ?>
53
+ --EXPECT--
54
+ OK!
0 commit comments