Skip to content

Fix PHP 8.5 deprecations of (integer), (long) and (boolean) casts #1758

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 2 commits into from
Aug 20, 2025

Conversation

mickverm
Copy link
Contributor

My goal was to fix the following deprecations when using this library on PHP 8.5(-rc):

Deprecated: Non-canonical cast (integer) is deprecated, use the (int) cast instead in /app/vendor/mongodb/mongodb/src/functions.php on line 412
Deprecated: Non-canonical cast (integer) is deprecated, use the (int) cast instead in /app/vendor/mongodb/mongodb/src/functions.php on line 413

In order to do this, I updated rector/rector to ^2.1.4 so that I could make use of the RenameCastRector-rule. In the meantime, I also modernized the rector configuration.

I opted to fix this on the v1.21 branch, I could rebase this on any other branch if deemed required.

@Copilot Copilot AI review requested due to automatic review settings August 19, 2025 12:37
@mickverm mickverm requested a review from a team as a code owner August 19, 2025 12:37
@mickverm mickverm requested a review from paulinevos August 19, 2025 12:37
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses PHP 8.5 deprecation warnings by replacing non-canonical cast syntax with modern canonical equivalents. The PR updates cast expressions from (integer), (boolean), and (double) to their canonical forms (int), (bool), and (float) respectively, and modernizes string function usage by replacing strpos() checks with str_contains().

  • Updates all cast expressions to use canonical PHP syntax
  • Modernizes string containment checks using str_contains()
  • Updates rector/rector dependency and configuration to enable automated fixes

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
composer.json Updates rector/rector dependency to ^2.1.4
rector.php Modernizes rector configuration and adds RenameCastRector rule
src/functions.php Fixes deprecated (integer) casts to (int)
src/Operation/*.php Updates deprecated cast expressions in operation classes
src/Model/*.php Replaces deprecated casts in model classes
src/GridFS/*.php Updates cast expressions in GridFS components
src/MapReduceResult.php Fixes deprecated cast in MapReduceResult
tests/**/*.php Updates deprecated casts in test files
tools/*.php Modernizes string containment checks using str_contains()

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

$rectorConfig->rule(StaticDataProviderClassMethodRector::class);

])
->withPhpSets(php74: true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

php74: true could be dropped in order to automatically upgrade the code to the PHP version defined in composer.json, 8.1 in this case. Doing this changes over 250 files.

@mickverm mickverm force-pushed the php-85-deprecations branch from 34e07d0 to 602fc2e Compare August 19, 2025 12:45
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

Thanks for these early fixes.
I think we'll abandon the 1.21 branch before the release of PHP 8.5, but there's no reason not to apply this simple changes to this branch.

@GromNaN GromNaN changed the title Fix PHP 8.5 deprecations. Fix PHP 8.5 deprecations of (integer), (long) and (boolean) casts Aug 20, 2025
@GromNaN GromNaN merged commit 062a19c into mongodb:v1.21 Aug 20, 2025
31 checks passed
@mickverm mickverm deleted the php-85-deprecations branch August 20, 2025 12:38
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