From baf90640dc9bd439543ad57c803f77f3e3381ee3 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 25 Jul 2024 12:03:34 +0200 Subject: [PATCH 01/10] PHPC-2412: Deprecate CursorId class --- php_phongo.c | 2 +- src/MongoDB/Cursor.c | 14 ++++++- src/MongoDB/Cursor.stub.php | 8 +++- src/MongoDB/CursorId.stub.php | 1 + src/MongoDB/CursorId_arginfo.h | 4 +- src/MongoDB/CursorInterface.stub.php | 7 +++- src/MongoDB/CursorInterface_arginfo.h | 20 ++++++++- src/MongoDB/Cursor_arginfo.h | 23 ++++++++++- tests/cursor/cursor-session-001.phpt | 4 +- tests/cursor/cursor-session-002.phpt | 4 +- tests/cursor/cursor-session-003.phpt | 4 +- tests/cursor/cursor-session-004.phpt | 4 +- tests/cursor/cursor-tailable_error-002.phpt | 2 +- tests/cursor/cursorid-getId-001.phpt | 45 +++++++++++++++++++++ tests/cursorid/cursorid-001.phpt | 1 + tests/cursorid/cursorid-002.phpt | 3 +- tests/functional/cursorid-001.phpt | 1 + 17 files changed, 126 insertions(+), 21 deletions(-) create mode 100644 tests/cursor/cursorid-getId-001.phpt diff --git a/php_phongo.c b/php_phongo.c index 516039327..8a81c41bb 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -253,8 +253,8 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_clientencryption_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_command_init_ce(INIT_FUNC_ARGS_PASSTHRU); - php_phongo_cursor_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_cursorid_init_ce(INIT_FUNC_ARGS_PASSTHRU); + php_phongo_cursor_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_manager_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_query_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_readconcern_init_ce(INIT_FUNC_ARGS_PASSTHRU); diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 96bf61fea..a07a4de91 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -143,12 +143,22 @@ static PHP_METHOD(MongoDB_Driver_Cursor, toArray) static PHP_METHOD(MongoDB_Driver_Cursor, getId) { php_phongo_cursor_t* intern; + bool asInt64; intern = Z_CURSOR_OBJ_P(getThis()); - PHONGO_PARSE_PARAMETERS_NONE(); + PHONGO_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_BOOL(asInt64) + PHONGO_PARSE_PARAMETERS_END(); - php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor)); + if (asInt64) { + phongo_int64_new(return_value, mongoc_cursor_get_id(intern->cursor)); + } else { + php_error_docref(NULL, E_DEPRECATED, "The method \"MongoDB\\Driver\\Cursor::getId\" will no longer return a \"MongoDB\\Driver\\CursorId\" instance in the future. Pass \"true\" as argument to change to the new behavior and receive a \"MongoDB\\BSON\\Int64\" instance instead."); + + php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor)); + } } /* Returns the Server object to which this cursor is attached */ diff --git a/src/MongoDB/Cursor.stub.php b/src/MongoDB/Cursor.stub.php index b0007046c..252ab65b8 100644 --- a/src/MongoDB/Cursor.stub.php +++ b/src/MongoDB/Cursor.stub.php @@ -18,7 +18,13 @@ public function current(): array|object|null {} public function current() {} #endif - final public function getId(): CursorId {} +#if PHP_VERSION_ID >= 80000 + /** @tentative-return-type */ + final public function getId(bool $asInt64 = false): CursorId|\MongoDB\BSON\Int64 {} +#else + /** @return CursorId|\MongoDB\BSON\Int64 */ + final public function getId(bool $asInt64 = false) {} +#endif final public function getServer(): Server {} diff --git a/src/MongoDB/CursorId.stub.php b/src/MongoDB/CursorId.stub.php index d283f6958..a9360fb81 100644 --- a/src/MongoDB/CursorId.stub.php +++ b/src/MongoDB/CursorId.stub.php @@ -7,6 +7,7 @@ namespace MongoDB\Driver; +/** @deprecated deprecated without replacement */ final class CursorId implements \Serializable { final private function __construct() {} diff --git a/src/MongoDB/CursorId_arginfo.h b/src/MongoDB/CursorId_arginfo.h index f6d0b8e9a..a893b1ef0 100644 --- a/src/MongoDB/CursorId_arginfo.h +++ b/src/MongoDB/CursorId_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 7f5bb1818756794e7ac1d2fe75f1a0f3d8d710a1 */ + * Stub hash: 857b13ac89a77f86aaac34eedba8ac836d0ca526 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_CursorId___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -69,7 +69,7 @@ static zend_class_entry *register_class_MongoDB_Driver_CursorId(zend_class_entry INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "CursorId", class_MongoDB_Driver_CursorId_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); - class_entry->ce_flags |= ZEND_ACC_FINAL; + class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_DEPRECATED; zend_class_implements(class_entry, 1, class_entry_Serializable); return class_entry; diff --git a/src/MongoDB/CursorInterface.stub.php b/src/MongoDB/CursorInterface.stub.php index 112555e8b..1501659f3 100644 --- a/src/MongoDB/CursorInterface.stub.php +++ b/src/MongoDB/CursorInterface.stub.php @@ -9,8 +9,13 @@ interface CursorInterface extends \Traversable { +#if PHP_VERSION_ID >= 80000 /** @tentative-return-type */ - public function getId(): CursorId; + public function getId(): CursorId|\MongoDB\BSON\Int64; +#else + /** @return CursorId|\MongoDB\BSON\Int64 */ + public function getId(); +#endif /** @tentative-return-type */ public function getServer(): Server; diff --git a/src/MongoDB/CursorInterface_arginfo.h b/src/MongoDB/CursorInterface_arginfo.h index 5ebecdae3..2bf1cb51c 100644 --- a/src/MongoDB/CursorInterface_arginfo.h +++ b/src/MongoDB/CursorInterface_arginfo.h @@ -1,8 +1,15 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 001f88edb710125420178d78e291fffc10bbfa1b */ + * Stub hash: 191d790b04cda72e9949774fad866f7750de5dfa */ -ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_CursorInterface_getId, 0, 0, MongoDB\\Driver\\CursorId, 0) +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_MongoDB_Driver_CursorInterface_getId, 0, 0, MongoDB\\Driver\\CursorId|MongoDB\\BSON\\Int64, 0) ZEND_END_ARG_INFO() +#endif + +#if !(PHP_VERSION_ID >= 80000) +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_CursorInterface_getId, 0, 0, 0) +ZEND_END_ARG_INFO() +#endif ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_CursorInterface_getServer, 0, 0, MongoDB\\Driver\\Server, 0) ZEND_END_ARG_INFO() @@ -18,10 +25,19 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_C ZEND_END_ARG_INFO() +#if PHP_VERSION_ID >= 80000 +#endif +#if !(PHP_VERSION_ID >= 80000) +#endif static const zend_function_entry class_MongoDB_Driver_CursorInterface_methods[] = { +#if PHP_VERSION_ID >= 80000 + ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_CursorInterface, getId, arginfo_class_MongoDB_Driver_CursorInterface_getId, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) +#endif +#if !(PHP_VERSION_ID >= 80000) ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_CursorInterface, getId, arginfo_class_MongoDB_Driver_CursorInterface_getId, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) +#endif ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_CursorInterface, getServer, arginfo_class_MongoDB_Driver_CursorInterface_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_CursorInterface, isDead, arginfo_class_MongoDB_Driver_CursorInterface_isDead, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) ZEND_ABSTRACT_ME_WITH_FLAGS(MongoDB_Driver_CursorInterface, setTypeMap, arginfo_class_MongoDB_Driver_CursorInterface_setTypeMap, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT) diff --git a/src/MongoDB/Cursor_arginfo.h b/src/MongoDB/Cursor_arginfo.h index f8c14b9c9..1874a4592 100644 --- a/src/MongoDB/Cursor_arginfo.h +++ b/src/MongoDB/Cursor_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: b94c509926df512855559d2c0ab4263b9d7dec63 */ + * Stub hash: e5e70f4036534c5aff1d55106e776e0230de53a6 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Cursor___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -14,8 +14,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Cursor_current, 0, 0, 0) ZEND_END_ARG_INFO() #endif -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Cursor_getId, 0, 0, MongoDB\\Driver\\CursorId, 0) +#if PHP_VERSION_ID >= 80000 +ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_MongoDB_Driver_Cursor_getId, 0, 0, MongoDB\\Driver\\CursorId|MongoDB\\BSON\\Int64, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, asInt64, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() +#endif + +#if !(PHP_VERSION_ID >= 80000) +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Cursor_getId, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, asInt64, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() +#endif ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Cursor_getServer, 0, 0, MongoDB\\Driver\\Server, 0) ZEND_END_ARG_INFO() @@ -48,7 +57,12 @@ static ZEND_METHOD(MongoDB_Driver_Cursor, current); #if !(PHP_VERSION_ID >= 80000) static ZEND_METHOD(MongoDB_Driver_Cursor, current); #endif +#if PHP_VERSION_ID >= 80000 +static ZEND_METHOD(MongoDB_Driver_Cursor, getId); +#endif +#if !(PHP_VERSION_ID >= 80000) static ZEND_METHOD(MongoDB_Driver_Cursor, getId); +#endif static ZEND_METHOD(MongoDB_Driver_Cursor, getServer); static ZEND_METHOD(MongoDB_Driver_Cursor, isDead); static ZEND_METHOD(MongoDB_Driver_Cursor, key); @@ -67,7 +81,12 @@ static const zend_function_entry class_MongoDB_Driver_Cursor_methods[] = { #if !(PHP_VERSION_ID >= 80000) ZEND_ME(MongoDB_Driver_Cursor, current, arginfo_class_MongoDB_Driver_Cursor_current, ZEND_ACC_PUBLIC) #endif +#if PHP_VERSION_ID >= 80000 + ZEND_ME(MongoDB_Driver_Cursor, getId, arginfo_class_MongoDB_Driver_Cursor_getId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) +#endif +#if !(PHP_VERSION_ID >= 80000) ZEND_ME(MongoDB_Driver_Cursor, getId, arginfo_class_MongoDB_Driver_Cursor_getId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) +#endif ZEND_ME(MongoDB_Driver_Cursor, getServer, arginfo_class_MongoDB_Driver_Cursor_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Cursor, isDead, arginfo_class_MongoDB_Driver_Cursor_isDead, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Cursor, key, arginfo_class_MongoDB_Driver_Cursor_key, ZEND_ACC_PUBLIC) diff --git a/tests/cursor/cursor-session-001.phpt b/tests/cursor/cursor-session-001.phpt index ade67b842..efa7799dd 100644 --- a/tests/cursor/cursor-session-001.phpt +++ b/tests/cursor/cursor-session-001.phpt @@ -26,7 +26,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -35,7 +35,7 @@ $iterator->next(); * is exhausted. While this is primarily done to ensure implicit sessions for * command cursors are returned to the pool ASAP, it also applies to explicit * sessions. */ -printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-002.phpt b/tests/cursor/cursor-session-002.phpt index 4332f7c12..840eb7ccc 100644 --- a/tests/cursor/cursor-session-002.phpt +++ b/tests/cursor/cursor-session-002.phpt @@ -28,12 +28,12 @@ $iterator->next(); /* Implicit sessions for query cursors are never exposed to PHPC, as they are * handled internally by libmongoc. Cursor debug ouput should never report such * sessions. */ -printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); -printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-003.phpt b/tests/cursor/cursor-session-003.phpt index df9f7d46e..91b5a796d 100644 --- a/tests/cursor/cursor-session-003.phpt +++ b/tests/cursor/cursor-session-003.phpt @@ -30,7 +30,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -39,7 +39,7 @@ $iterator->next(); * is exhausted. While this is primarily done to ensure implicit sessions for * command cursors are returned to the pool ASAP, it also applies to explicit * sessions. */ -printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-004.phpt b/tests/cursor/cursor-session-004.phpt index b93bbbf08..f792276b9 100644 --- a/tests/cursor/cursor-session-004.phpt +++ b/tests/cursor/cursor-session-004.phpt @@ -29,7 +29,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -38,7 +38,7 @@ $iterator->next(); * libmongoc, PHPC-1152 emulates its own implicit sessions for command cursors * in order to ensure that command cursors always share the same session as the * originating command. */ -printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-tailable_error-002.phpt b/tests/cursor/cursor-tailable_error-002.phpt index 9157c5e2d..dec2d52c6 100644 --- a/tests/cursor/cursor-tailable_error-002.phpt +++ b/tests/cursor/cursor-tailable_error-002.phpt @@ -57,7 +57,7 @@ echo throws(function() use ($manager) { if ($numAwaitAttempts === 5) { $cursor->getServer()->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command([ 'killCursors' => COLLECTION_NAME, - 'cursors' => [ $cursor->getId() ], + 'cursors' => [ $cursor->getId(true) ], ])); } diff --git a/tests/cursor/cursorid-getId-001.phpt b/tests/cursor/cursorid-getId-001.phpt new file mode 100644 index 000000000..73f8b6c19 --- /dev/null +++ b/tests/cursor/cursorid-getId-001.phpt @@ -0,0 +1,45 @@ +--TEST-- +MongoDB\Driver\Cursor::getId +--SKIPIF-- + + + +--FILE-- +insert(['_id' => 1]); +$bulk->insert(['_id' => 2]); +$bulk->insert(['_id' => 3]); +$manager->executeBulkWrite(NS, $bulk); + +$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2])); + +var_dump($cursor->getId()); +var_dump($cursor->getId(false)); +var_dump($cursor->getId(true)); + +?> +===DONE=== + +--EXPECTF-- +Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s +object(MongoDB\Driver\CursorId)#%d (%d) { + ["id"]=> + int(%d) +} + +Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s +object(MongoDB\Driver\CursorId)#%d (%d) { + ["id"]=> + int(%d) +} +object(MongoDB\BSON\Int64)#%d (%d) { + ["integer"]=> + string(19) "%d" +} +===DONE=== diff --git a/tests/cursorid/cursorid-001.phpt b/tests/cursorid/cursorid-001.phpt index 34cfbbc3e..6cf970223 100644 --- a/tests/cursorid/cursorid-001.phpt +++ b/tests/cursorid/cursorid-001.phpt @@ -26,6 +26,7 @@ hex_dump(fromPHP(['cid' => $cursorId])); ===DONE=== --EXPECTF-- +Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s 0 : 12 00 00 00 12 63 69 64 00 %x %x %x %x %x %x %x [.....cid.%s] 10 : %x 00 [%s.] ===DONE=== diff --git a/tests/cursorid/cursorid-002.phpt b/tests/cursorid/cursorid-002.phpt index 23c053894..5809fd218 100644 --- a/tests/cursorid/cursorid-002.phpt +++ b/tests/cursorid/cursorid-002.phpt @@ -37,7 +37,8 @@ printf("Killed expected cursor: %s\n", (string) $cursorId === (string) $result-> ?> ===DONE=== ---EXPECT-- +--EXPECTF-- +Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s Killed 1 cursor(s) Killed expected cursor: yes ===DONE=== diff --git a/tests/functional/cursorid-001.phpt b/tests/functional/cursorid-001.phpt index 026b20c2a..09654643d 100644 --- a/tests/functional/cursorid-001.phpt +++ b/tests/functional/cursorid-001.phpt @@ -32,6 +32,7 @@ var_dump($s1 > 0); ===DONE=== --EXPECTF-- +Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s object(MongoDB\Driver\CursorId)#%d (%d) { ["id"]=> %rint\(\d+\)|string\(\d+\) "\d+"%r From 1b5c2e96d6b5d055d40dc8bc9b61445c01d152a8 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 25 Jul 2024 12:38:18 +0200 Subject: [PATCH 02/10] Use zend_bool instead of bool --- src/MongoDB/Cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index a07a4de91..98067e999 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -143,7 +143,7 @@ static PHP_METHOD(MongoDB_Driver_Cursor, toArray) static PHP_METHOD(MongoDB_Driver_Cursor, getId) { php_phongo_cursor_t* intern; - bool asInt64; + zend_bool asInt64; intern = Z_CURSOR_OBJ_P(getThis()); From 9e5f6140b82ace4ea0d1a1abcb41ee03831a2314 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 25 Jul 2024 13:30:57 +0200 Subject: [PATCH 03/10] Remove fixed length assertion in test --- tests/cursor/cursorid-getId-001.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cursor/cursorid-getId-001.phpt b/tests/cursor/cursorid-getId-001.phpt index 73f8b6c19..78aa8144e 100644 --- a/tests/cursor/cursorid-getId-001.phpt +++ b/tests/cursor/cursorid-getId-001.phpt @@ -40,6 +40,6 @@ object(MongoDB\Driver\CursorId)#%d (%d) { } object(MongoDB\BSON\Int64)#%d (%d) { ["integer"]=> - string(19) "%d" + string(%d) "%d" } ===DONE=== From 6a7187d6480a0a8e8d2df4ad14b7cf3ecc0a62c7 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 25 Jul 2024 13:31:07 +0200 Subject: [PATCH 04/10] Correctly set default parameter value --- src/MongoDB/Cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 98067e999..a48e27ce7 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -143,7 +143,7 @@ static PHP_METHOD(MongoDB_Driver_Cursor, toArray) static PHP_METHOD(MongoDB_Driver_Cursor, getId) { php_phongo_cursor_t* intern; - zend_bool asInt64; + zend_bool asInt64 = false; intern = Z_CURSOR_OBJ_P(getThis()); From 6143507f560b49030eed9915578471f221981edb Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 25 Jul 2024 13:48:35 +0200 Subject: [PATCH 05/10] Remove int cast to avoid warnings on 32-bit platforms --- tests/cursor/cursor-session-001.phpt | 4 ++-- tests/cursor/cursor-session-002.phpt | 4 ++-- tests/cursor/cursor-session-003.phpt | 4 ++-- tests/cursor/cursor-session-004.phpt | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/cursor/cursor-session-001.phpt b/tests/cursor/cursor-session-001.phpt index efa7799dd..e5f0ef66f 100644 --- a/tests/cursor/cursor-session-001.phpt +++ b/tests/cursor/cursor-session-001.phpt @@ -26,7 +26,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -35,7 +35,7 @@ $iterator->next(); * is exhausted. While this is primarily done to ensure implicit sessions for * command cursors are returned to the pool ASAP, it also applies to explicit * sessions. */ -printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-002.phpt b/tests/cursor/cursor-session-002.phpt index 840eb7ccc..b8827c2c4 100644 --- a/tests/cursor/cursor-session-002.phpt +++ b/tests/cursor/cursor-session-002.phpt @@ -28,12 +28,12 @@ $iterator->next(); /* Implicit sessions for query cursors are never exposed to PHPC, as they are * handled internally by libmongoc. Cursor debug ouput should never report such * sessions. */ -printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); -printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-003.phpt b/tests/cursor/cursor-session-003.phpt index 91b5a796d..2eabbe616 100644 --- a/tests/cursor/cursor-session-003.phpt +++ b/tests/cursor/cursor-session-003.phpt @@ -30,7 +30,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -39,7 +39,7 @@ $iterator->next(); * is exhausted. While this is primarily done to ensure implicit sessions for * command cursors are returned to the pool ASAP, it also applies to explicit * sessions. */ -printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-004.phpt b/tests/cursor/cursor-session-004.phpt index f792276b9..1fc23ffef 100644 --- a/tests/cursor/cursor-session-004.phpt +++ b/tests/cursor/cursor-session-004.phpt @@ -29,7 +29,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -38,7 +38,7 @@ $iterator->next(); * libmongoc, PHPC-1152 emulates its own implicit sessions for command cursors * in order to ensure that command cursors always share the same session as the * originating command. */ -printf("\nCursor ID is zero: %s\n", (int) $cursor->getId(true) === 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); var_dump($cursor); ?> From 48da73ce41543a11fec4e95c38643c09352a744c Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 2 Sep 2024 10:49:07 +0200 Subject: [PATCH 06/10] Fix wrong expectation for CursorId debug format --- tests/cursor/cursorid-getId-001.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cursor/cursorid-getId-001.phpt b/tests/cursor/cursorid-getId-001.phpt index 78aa8144e..fd168d8ee 100644 --- a/tests/cursor/cursorid-getId-001.phpt +++ b/tests/cursor/cursorid-getId-001.phpt @@ -30,13 +30,13 @@ var_dump($cursor->getId(true)); Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s object(MongoDB\Driver\CursorId)#%d (%d) { ["id"]=> - int(%d) + %rint\(%d\)|string\(%d\) "%d"%r } Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s object(MongoDB\Driver\CursorId)#%d (%d) { ["id"]=> - int(%d) + %rint\(%d\)|string\(%d\) "%d"%r } object(MongoDB\BSON\Int64)#%d (%d) { ["integer"]=> From d3ea5dd38f5c6132f858fba1809885cf89d40bf8 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 4 Sep 2024 09:30:59 +0200 Subject: [PATCH 07/10] Use new cursor ID logic in tests where possible --- tests/cursorid/cursorid-002.phpt | 5 ++--- tests/functional/cursorid-001.phpt | 18 ++++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/cursorid/cursorid-002.phpt b/tests/cursorid/cursorid-002.phpt index 5809fd218..808ac485d 100644 --- a/tests/cursorid/cursorid-002.phpt +++ b/tests/cursorid/cursorid-002.phpt @@ -21,7 +21,7 @@ $bulk->insert(['_id' => 3]); $server->executeBulkWrite(NS, $bulk); $cursor = $server->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2])); -$cursorId = $cursor->getId(); +$cursorId = $cursor->getId(true); $command = new MongoDB\Driver\Command([ 'killCursors' => COLLECTION_NAME, @@ -32,13 +32,12 @@ $command = new MongoDB\Driver\Command([ * unserializing the result document requires a 64-bit platform. */ $result = $server->executeCommand(DATABASE_NAME, $command)->toArray()[0]; printf("Killed %d cursor(s)\n", count($result->cursorsKilled)); -printf("Killed expected cursor: %s\n", (string) $cursorId === (string) $result->cursorsKilled[0] ? 'yes' : 'no'); +printf("Killed expected cursor: %s\n", $cursorId == $result->cursorsKilled[0] ? 'yes' : 'no'); ?> ===DONE=== --EXPECTF-- -Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s Killed 1 cursor(s) Killed expected cursor: yes ===DONE=== diff --git a/tests/functional/cursorid-001.phpt b/tests/functional/cursorid-001.phpt index 09654643d..ec9742437 100644 --- a/tests/functional/cursorid-001.phpt +++ b/tests/functional/cursorid-001.phpt @@ -20,23 +20,17 @@ $query = new MongoDB\Driver\Query(array(), array( $cursor = $manager->executeQuery(NS, $query); -$cursorid = $cursor->getId(); -$s1 = (string)$cursorid; -var_dump( - $cursorid, - $s1 -); -var_dump($s1 > 0); +$cursorid = $cursor->getId(true); +var_dump($cursorid); +var_dump($cursorid != 0); ?> ===DONE=== --EXPECTF-- -Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - %rint\(\d+\)|string\(\d+\) "\d+"%r +object(MongoDB\BSON\Int64)#%d (%d) { + ["integer"]=> + string(%d) "%d" } -string(%d) "%d" bool(true) ===DONE=== From 9aac2e8f72c79a854024beb7309602a31f53f955 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Wed, 4 Sep 2024 09:39:18 +0200 Subject: [PATCH 08/10] Remove deprecation comment from CursorId stub --- src/MongoDB/CursorId.stub.php | 1 - src/MongoDB/CursorId_arginfo.h | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/MongoDB/CursorId.stub.php b/src/MongoDB/CursorId.stub.php index a9360fb81..d283f6958 100644 --- a/src/MongoDB/CursorId.stub.php +++ b/src/MongoDB/CursorId.stub.php @@ -7,7 +7,6 @@ namespace MongoDB\Driver; -/** @deprecated deprecated without replacement */ final class CursorId implements \Serializable { final private function __construct() {} diff --git a/src/MongoDB/CursorId_arginfo.h b/src/MongoDB/CursorId_arginfo.h index a893b1ef0..f6d0b8e9a 100644 --- a/src/MongoDB/CursorId_arginfo.h +++ b/src/MongoDB/CursorId_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 857b13ac89a77f86aaac34eedba8ac836d0ca526 */ + * Stub hash: 7f5bb1818756794e7ac1d2fe75f1a0f3d8d710a1 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_CursorId___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -69,7 +69,7 @@ static zend_class_entry *register_class_MongoDB_Driver_CursorId(zend_class_entry INIT_NS_CLASS_ENTRY(ce, "MongoDB\\Driver", "CursorId", class_MongoDB_Driver_CursorId_methods); class_entry = zend_register_internal_class_ex(&ce, NULL); - class_entry->ce_flags |= ZEND_ACC_FINAL|ZEND_ACC_DEPRECATED; + class_entry->ce_flags |= ZEND_ACC_FINAL; zend_class_implements(class_entry, 1, class_entry_Serializable); return class_entry; From a3cbc53f436a456e011ef6e00c160ead8268814a Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 5 Sep 2024 12:33:33 +0200 Subject: [PATCH 09/10] Restore cursorid serialisation test --- tests/cursorid/cursorid-002.phpt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/cursorid/cursorid-002.phpt b/tests/cursorid/cursorid-002.phpt index 808ac485d..5809fd218 100644 --- a/tests/cursorid/cursorid-002.phpt +++ b/tests/cursorid/cursorid-002.phpt @@ -21,7 +21,7 @@ $bulk->insert(['_id' => 3]); $server->executeBulkWrite(NS, $bulk); $cursor = $server->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2])); -$cursorId = $cursor->getId(true); +$cursorId = $cursor->getId(); $command = new MongoDB\Driver\Command([ 'killCursors' => COLLECTION_NAME, @@ -32,12 +32,13 @@ $command = new MongoDB\Driver\Command([ * unserializing the result document requires a 64-bit platform. */ $result = $server->executeCommand(DATABASE_NAME, $command)->toArray()[0]; printf("Killed %d cursor(s)\n", count($result->cursorsKilled)); -printf("Killed expected cursor: %s\n", $cursorId == $result->cursorsKilled[0] ? 'yes' : 'no'); +printf("Killed expected cursor: %s\n", (string) $cursorId === (string) $result->cursorsKilled[0] ? 'yes' : 'no'); ?> ===DONE=== --EXPECTF-- +Deprecated: MongoDB\Driver\Cursor::getId(): The method "MongoDB\Driver\Cursor::getId" will no longer return a "MongoDB\Driver\CursorId" instance in the future. Pass "true" as argument to change to the new behavior and receive a "MongoDB\BSON\Int64" instance instead. in %s Killed 1 cursor(s) Killed expected cursor: yes ===DONE=== From 62a33929d2fe7a71bdcc5d391eef967a9a1d3d2e Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 5 Sep 2024 12:35:39 +0200 Subject: [PATCH 10/10] Restore original class initialisation order --- php_phongo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_phongo.c b/php_phongo.c index 8a81c41bb..516039327 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -253,8 +253,8 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_clientencryption_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_command_init_ce(INIT_FUNC_ARGS_PASSTHRU); - php_phongo_cursorid_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_cursor_init_ce(INIT_FUNC_ARGS_PASSTHRU); + php_phongo_cursorid_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_manager_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_query_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_readconcern_init_ce(INIT_FUNC_ARGS_PASSTHRU);