Skip to content

PHPC-2346: Remove deprecated BSON functions #1653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 18, 2024

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Sep 17, 2024

PHPC-2346

This removes the BSON functions that were deprecated in favour of the MongoDB\BSON\Document class.

@alcaeus alcaeus requested a review from jmikola September 17, 2024 07:36
@alcaeus alcaeus force-pushed the phpc-2346-remove-bson-functions branch from 27f9f43 to 9f1e2bc Compare September 17, 2024 09:41
@alcaeus
Copy link
Member Author

alcaeus commented Sep 17, 2024

Waiting on #1652 to be merged to add the upgrade note.

@alcaeus alcaeus requested review from GromNaN and jmikola and removed request for jmikola and GromNaN September 17, 2024 11:35
/* Note: Although libbson can parse the extended JSON representation for
* 64-bit integers (i.e. "$numberLong"), it currently prints them as
* doubles (see: https://jira.mongodb.org/browse/CDRIVER-375). */
printf("Test %s\n", MongoDB\BSON\toJSON($bson));
hex_dump($bson);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was asserting the parsed BSON not relevant to this test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parsed BSON is printed as part of the debug data of a MongoDB\BSON\Document instance. It prints the BSON bytes (base64 encoded for easier handling) as well as the PHP representation, so there's no need to use hex_dump as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I overlooked the "data" field in the debug output. 👍

int(-2147483648)
object(MongoDB\BSON\Int64)#%d (%d) {
["integer"]=>
string(11) "-2147483648"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is related to changing toPHP(fromJSON(...)) to Document::fromJSON(...)->toPHP(), but don't the toPHP() functions use the same logic internally? Just curious why this might have changed.

The current output seems more correct, as the JSON input is clearly a 64-bit integer type regardless of its value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is pretty much the only notable difference between the two implementations. Interacting with a MongoDB\BSON\Document instance will always yield an Int64 instance for 64-bit integers, even when they fall within the 32-bit range. This will not matter in most cases as an Int64 can be coerced to an int and also used in operations as if it were an integer.

@alcaeus alcaeus force-pushed the phpc-2346-remove-bson-functions branch from 9f1e2bc to 96eac6d Compare September 18, 2024 07:16
@alcaeus alcaeus requested a review from jmikola September 18, 2024 07:46
@alcaeus alcaeus enabled auto-merge (squash) September 18, 2024 07:46
@alcaeus alcaeus force-pushed the phpc-2346-remove-bson-functions branch from 96eac6d to e4a1333 Compare September 18, 2024 07:54
@alcaeus alcaeus merged commit 4eeff7f into mongodb:v2.x Sep 18, 2024
62 checks passed
@alcaeus alcaeus deleted the phpc-2346-remove-bson-functions branch September 18, 2024 13:56
alcaeus added a commit that referenced this pull request Oct 29, 2024
* v2.x: (22 commits)
  PHPC-2441: Remove deprecated Manager constructor options (#1719)
  PHPC-990: Strict type validation for boolean URI options (#1713)
  PHPC-2440: Remove deprecated Query constructor options (#1707)
  PHPC-2459: Remove support for float arg in UTCDateTime ctor (#1709)
  Remove obsolete test
  PHPC-2344 Remove SSLConnectionException (#1696)
  PHPC-2144 Throw a LogicException when getting info from unacknowledged write result (#1687)
  PHPC-2454: Remove --enable-system-ciphers configure option (#1681)
  PHPC-2348 Remove `WriteException` and move `getWriteResult` to `BulkWriteException` (#1685)
  PHPC-2417 Add UTCDateTimeInterface::toDateTimeImmutable() (#1684)
  PHPC-2309: Remove --with-openssl-dir configure option (#1676)
  PHPC-2444: Remove support for string arguments in UTCDateTime constructor (#1662)
  PHPC-2248: Remove Serializable implementations (#1663)
  Update version for 2.x branch (#1672)
  PHPC-1021: Remove support for ReadPreference integer modes (#1666)
  PHPC-2342: Remove --with-libbson and --with-libmongoc configure options (#1667)
  PHPC-2351: Remove CursorId class (#1664)
  PHPC-2140: Make tentative return types definitive (#1658)
  PHPC-2402: Remove range_preview constants (#1665)
  PHPC-2346: Remove deprecated BSON functions (#1653)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants