Skip to content

Commit c0dbf15

Browse files
committed
Add tests for PHPC-1839 for PHP >= 8.1
1 parent 25b64f7 commit c0dbf15

File tree

4 files changed

+217
-0
lines changed

4 files changed

+217
-0
lines changed

tests/bson/bug1839-005.phpt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
--TEST--
2+
PHPC-1839: Referenced, out-of-scope, non-interned string in typeMap (PHP >= 8.1)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.1'); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
function createTypemap()
11+
{
12+
// Assemble the string so as to not have an interned string
13+
$rootValue = chr(ord('a')) . 'rray';
14+
$documentValue = chr(ord('a')) . 'rray';
15+
16+
// Use a reference to this non-interned string in the type map
17+
$typemap = ['root' => &$rootValue, 'document' => &$documentValue];
18+
19+
return $typemap;
20+
}
21+
22+
$typemap = createTypemap();
23+
$bson = MongoDB\BSON\fromPhp((object) []);
24+
25+
echo "Before:\n";
26+
debug_zval_dump($typemap);
27+
28+
MongoDB\BSON\toPHP($bson, $typemap);
29+
30+
echo "After:\n";
31+
debug_zval_dump($typemap);
32+
33+
?>
34+
===DONE===
35+
<?php exit(0); ?>
36+
--EXPECT--
37+
Before:
38+
array(2) refcount(2){
39+
["root"]=>
40+
reference refcount(1) {
41+
string(5) "array" refcount(1)
42+
}
43+
["document"]=>
44+
reference refcount(1) {
45+
string(5) "array" refcount(1)
46+
}
47+
}
48+
After:
49+
array(2) refcount(2){
50+
["root"]=>
51+
reference refcount(1) {
52+
string(5) "array" refcount(1)
53+
}
54+
["document"]=>
55+
reference refcount(1) {
56+
string(5) "array" refcount(1)
57+
}
58+
}
59+
===DONE===

tests/bson/bug1839-006.phpt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
PHPC-1839: Referenced, local, non-interned string in typeMap (PHP >= 8.1)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.1'); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
// Assemble the string so as to not have an interned string
11+
$rootValue = chr(ord('a')) . 'rray';
12+
$documentValue = chr(ord('a')) . 'rray';
13+
14+
$typemap = ['root' => &$rootValue, 'document' => &$documentValue];
15+
$bson = MongoDB\BSON\fromPhp((object) []);
16+
17+
echo "Before:\n";
18+
debug_zval_dump($typemap);
19+
20+
MongoDB\BSON\toPHP($bson, $typemap);
21+
22+
echo "After:\n";
23+
debug_zval_dump($typemap);
24+
25+
?>
26+
===DONE===
27+
<?php exit(0); ?>
28+
--EXPECT--
29+
Before:
30+
array(2) refcount(2){
31+
["root"]=>
32+
reference refcount(2) {
33+
string(5) "array" refcount(1)
34+
}
35+
["document"]=>
36+
reference refcount(2) {
37+
string(5) "array" refcount(1)
38+
}
39+
}
40+
After:
41+
array(2) refcount(2){
42+
["root"]=>
43+
reference refcount(2) {
44+
string(5) "array" refcount(1)
45+
}
46+
["document"]=>
47+
reference refcount(2) {
48+
string(5) "array" refcount(1)
49+
}
50+
}
51+
===DONE===

tests/bson/bug1839-007.phpt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
PHPC-1839: Referenced, out-of-scope, interned string in typeMap (PHP >= 8.1)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.1'); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
function createTypemap()
11+
{
12+
$rootValue = 'array';
13+
$documentValue = 'array';
14+
15+
$typemap = ['root' => &$rootValue, 'document' => &$documentValue];
16+
17+
return $typemap;
18+
}
19+
20+
$typemap = createTypemap();
21+
$bson = MongoDB\BSON\fromPhp((object) []);
22+
23+
echo "Before:\n";
24+
debug_zval_dump($typemap);
25+
26+
MongoDB\BSON\toPHP($bson, $typemap);
27+
28+
echo "After:\n";
29+
debug_zval_dump($typemap);
30+
31+
?>
32+
===DONE===
33+
<?php exit(0); ?>
34+
--EXPECT--
35+
Before:
36+
array(2) refcount(2){
37+
["root"]=>
38+
reference refcount(1) {
39+
string(5) "array" interned
40+
}
41+
["document"]=>
42+
reference refcount(1) {
43+
string(5) "array" interned
44+
}
45+
}
46+
After:
47+
array(2) refcount(2){
48+
["root"]=>
49+
reference refcount(1) {
50+
string(5) "array" interned
51+
}
52+
["document"]=>
53+
reference refcount(1) {
54+
string(5) "array" interned
55+
}
56+
}
57+
===DONE===

tests/bson/bug1839-008.phpt

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--TEST--
2+
PHPC-1839: Referenced, local, interned string in typeMap (PHP >= 8.1)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.1'); ?>
6+
--FILE--
7+
<?php
8+
require_once __DIR__ . "/../utils/basic.inc";
9+
10+
$rootValue = 'array';
11+
$documentValue = 'array';
12+
13+
$typemap = ['root' => &$rootValue, 'document' => &$documentValue];
14+
$bson = MongoDB\BSON\fromPhp((object) []);
15+
16+
echo "Before:\n";
17+
debug_zval_dump($typemap);
18+
19+
MongoDB\BSON\toPHP($bson, $typemap);
20+
21+
echo "After:\n";
22+
debug_zval_dump($typemap);
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
Before:
29+
array(2) refcount(2){
30+
["root"]=>
31+
reference refcount(2) {
32+
string(5) "array" interned
33+
}
34+
["document"]=>
35+
reference refcount(2) {
36+
string(5) "array" interned
37+
}
38+
}
39+
After:
40+
array(2) refcount(2){
41+
["root"]=>
42+
reference refcount(2) {
43+
string(5) "array" interned
44+
}
45+
["document"]=>
46+
reference refcount(2) {
47+
string(5) "array" interned
48+
}
49+
}
50+
===DONE===

0 commit comments

Comments
 (0)