Skip to content

Commit b6d0908

Browse files
committed
PHPC-528: Support zval references when appending BSON
1 parent 5deb609 commit b6d0908

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/bson.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,9 @@ void object_to_bson(zval *object, php_phongo_bson_flags_t flags, const char *key
983983
}
984984
void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char *key, long key_len, int entry_type, zval *entry TSRMLS_DC)
985985
{
986+
#if PHP_VERSION_ID >= 70000
987+
try_again:
988+
#endif
986989
switch (entry_type)
987990
{
988991
case IS_NULL:
@@ -1045,6 +1048,11 @@ void phongo_bson_append(bson_t *bson, php_phongo_bson_flags_t flags, const char
10451048
case IS_INDIRECT:
10461049
phongo_bson_append(bson, flags, key, key_len, Z_TYPE_P(Z_INDIRECT_P(entry)), Z_INDIRECT_P(entry) TSRMLS_DC);
10471050
break;
1051+
1052+
case IS_REFERENCE:
1053+
ZVAL_DEREF(entry);
1054+
entry_type = Z_TYPE_P(entry);
1055+
goto try_again;
10481056
#endif
10491057

10501058
default:

tests/bson/bug0528.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
PHPC-528: Cannot append reference to BSON
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$embedded = ['foo'];
10+
$data = ['embedded' => &$embedded];
11+
12+
$bson = fromPHP($data);
13+
echo toJson(fromPHP($data)), "\n";
14+
15+
?>
16+
===DONE===
17+
<?php exit(0); ?>
18+
--EXPECT--
19+
{ "embedded" : [ "foo" ] }
20+
===DONE===

0 commit comments

Comments
 (0)