Skip to content

Commit b93ad4f

Browse files
committed
PHPC-148: var_dump()ing ObjectID should show the ObjectID
1 parent 9b5cd34 commit b93ad4f

File tree

2 files changed

+41
-16
lines changed

2 files changed

+41
-16
lines changed

src/BSON/ObjectID.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,6 @@ static zend_function_entry php_phongo_objectid_me[] = {
126126
/* }}} */
127127

128128

129-
/* {{{ Other functions */
130-
static int php_phongo_objectid_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
131-
{
132-
php_phongo_objectid_t *intern1;
133-
php_phongo_objectid_t *intern2;
134-
135-
intern1 = (php_phongo_objectid_t *)zend_object_store_get_object(o1 TSRMLS_CC);
136-
intern2 = (php_phongo_objectid_t *)zend_object_store_get_object(o2 TSRMLS_CC);
137-
138-
return strcmp(intern1->oid, intern2->oid);
139-
} /* }}} */
140-
/* }}} */
141129
/* {{{ php_phongo_objectid_t object handlers */
142130
static void php_phongo_objectid_free_object(void *object TSRMLS_DC) /* {{{ */
143131
{
@@ -163,6 +151,34 @@ zend_object_value php_phongo_objectid_create_object(zend_class_entry *class_type
163151

164152
return retval;
165153
} /* }}} */
154+
155+
static int php_phongo_objectid_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
156+
{
157+
php_phongo_objectid_t *intern1;
158+
php_phongo_objectid_t *intern2;
159+
160+
intern1 = (php_phongo_objectid_t *)zend_object_store_get_object(o1 TSRMLS_CC);
161+
intern2 = (php_phongo_objectid_t *)zend_object_store_get_object(o2 TSRMLS_CC);
162+
163+
return strcmp(intern1->oid, intern2->oid);
164+
} /* }}} */
165+
166+
HashTable *php_phongo_objectid_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
167+
{
168+
php_phongo_objectid_t *intern;
169+
zval retval = zval_used_for_init;
170+
171+
172+
*is_temp = 1;
173+
intern = (php_phongo_objectid_t *)zend_object_store_get_object(object TSRMLS_CC);
174+
175+
array_init_size(&retval, 6);
176+
177+
add_assoc_stringl_ex(&retval, ZEND_STRS("oid"), intern->oid, 24, 1);
178+
179+
return Z_ARRVAL(retval);
180+
181+
} /* }}} */
166182
/* }}} */
167183

168184
/* {{{ PHP_MINIT_FUNCTION */
@@ -179,6 +195,7 @@ PHP_MINIT_FUNCTION(ObjectID)
179195

180196
memcpy(&php_phongo_handler_objectid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
181197
php_phongo_handler_objectid.compare_objects = php_phongo_objectid_compare_objects;
198+
php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info;
182199

183200

184201
return SUCCESS;

tests/standalone/manager-executeWriteBatch-004.phpt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ matchedCount: 1
3333
modifiedCount: 1
3434
upsertedCount: 2
3535
deletedCount: 0
36-
upsertedId[0]: object(BSON\ObjectID)#%d (0) {
36+
upsertedId[0]: object(BSON\ObjectID)#%d (%d) {
37+
["oid"]=>
38+
string(24) "%s"
3739
}
38-
upsertedId[1]: object(BSON\ObjectID)#%d (0) {
40+
upsertedId[1]: object(BSON\ObjectID)#%d (%d) {
41+
["oid"]=>
42+
string(24) "%s"
3943
}
4044

4145
===> Collection
4246
array(2) {
4347
[0]=>
4448
array(3) {
4549
["_id"]=>
46-
object(BSON\ObjectID)#%d (0) {
50+
object(BSON\ObjectID)#%d (%d) {
51+
["oid"]=>
52+
string(24) "%s"
4753
}
4854
["x"]=>
4955
string(3) "foo"
@@ -53,7 +59,9 @@ array(2) {
5359
[1]=>
5460
array(3) {
5561
["_id"]=>
56-
object(BSON\ObjectID)#%d (0) {
62+
object(BSON\ObjectID)#%d (%d) {
63+
["oid"]=>
64+
string(24) "%s"
5765
}
5866
["x"]=>
5967
string(3) "bar"

0 commit comments

Comments
 (0)