Skip to content

Commit 2acbc5b

Browse files
committed
PHPC-137: var_dump()ing CursorID should show the Cursor ID
1 parent 1120b30 commit 2acbc5b

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/MongoDB/CursorId.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
PHONGO_API zend_class_entry *php_phongo_cursorid_ce;
4646

47+
zend_object_handlers php_phongo_handler_cursorid;
48+
4749
/* {{{ proto MongoDB\Driver\CursorId CursorId::__construct(string $id)
4850
Construct a new CursorId */
4951
PHP_METHOD(CursorId, __construct)
@@ -52,6 +54,7 @@ PHP_METHOD(CursorId, __construct)
5254
zend_error_handling error_handling;
5355
char *id;
5456
int id_len;
57+
(void)return_value; (void)return_value_ptr; (void)return_value_used;
5558

5659

5760
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
@@ -70,6 +73,7 @@ PHP_METHOD(CursorId, __toString)
7073
{
7174
php_phongo_cursorid_t *intern;
7275
zend_error_handling error_handling;
76+
(void)return_value_ptr; (void)return_value_used;
7377

7478

7579
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
@@ -124,32 +128,50 @@ static void php_phongo_cursorid_free_object(void *object TSRMLS_DC) /* {{{ */
124128
zend_object_value php_phongo_cursorid_create_object(zend_class_entry *class_type TSRMLS_DC) /* {{{ */
125129
{
126130
zend_object_value retval;
127-
php_phongo_cursorid_t *intern;
131+
php_phongo_cursorid_t *intern = NULL;
128132

129-
intern = (php_phongo_cursorid_t *)emalloc(sizeof(php_phongo_cursorid_t));
130-
memset(intern, 0, sizeof(php_phongo_cursorid_t));
133+
intern = (php_phongo_cursorid_t *)ecalloc(1, sizeof *intern);
131134

132135
zend_object_std_init(&intern->std, class_type TSRMLS_CC);
133136
object_properties_init(&intern->std, class_type);
134137

135138
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_cursorid_free_object, NULL TSRMLS_CC);
136-
retval.handlers = phongo_get_std_object_handlers();
139+
retval.handlers = &php_phongo_handler_cursorid;
137140

138141
return retval;
139142
} /* }}} */
143+
144+
HashTable *php_phongo_cursorid_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
145+
{
146+
php_phongo_cursorid_t *intern;
147+
zval retval = zval_used_for_init;
148+
149+
150+
*is_temp = 1;
151+
intern = (php_phongo_cursorid_t *)zend_object_store_get_object(object TSRMLS_CC);
152+
153+
array_init(&retval);
154+
155+
add_assoc_long_ex(&retval, ZEND_STRS("id"), intern->id);
156+
157+
return Z_ARRVAL(retval);
158+
159+
} /* }}} */
140160
/* }}} */
141161

142162
/* {{{ PHP_MINIT_FUNCTION */
143163
PHP_MINIT_FUNCTION(CursorId)
144164
{
145-
(void)type; /* We don't care if we are loaded via dl() or extension= */
165+
(void)type; (void)module_number;
146166
zend_class_entry ce;
147167

148168
INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "CursorId", php_phongo_cursorid_me);
149-
ce.create_object = php_phongo_cursorid_create_object;
150169
php_phongo_cursorid_ce = zend_register_internal_class(&ce TSRMLS_CC);
170+
php_phongo_cursorid_ce->create_object = php_phongo_cursorid_create_object;
151171
php_phongo_cursorid_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
152172

173+
memcpy(&php_phongo_handler_cursorid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
174+
php_phongo_handler_cursorid.get_debug_info = php_phongo_cursorid_get_debug_info;
153175

154176
return SUCCESS;
155177
}

tests/functional/cursorid-001.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ $cursor->kill();
3131
===DONE===
3232
<?php exit(0); ?>
3333
--EXPECTF--
34-
object(MongoDB\Driver\CursorId)#%d (0) {
34+
object(MongoDB\Driver\CursorId)#%d (%d) {
35+
["id"]=>
36+
%s(%d)
3537
}
3638
string(%d) "%d"
3739
===DONE===

0 commit comments

Comments
 (0)