Skip to content

Fix: PHP 8.4 compatibility issues for nullable parameters and return types - #335

Merged
armanist merged 3 commits into
quantum-php:masterfrom
Wiltzsu:feature/php-8.4-compatibility-fixes
Oct 21, 2025
Merged

armanist merged 3 commits into
quantum-php:masterfrom
Wiltzsu:feature/php-8.4-compatibility-fixes

Conversation

@Wiltzsu

@Wiltzsu Wiltzsu commented Oct 19, 2025

Copy link
Copy Markdown
Collaborator

What was changed

Fixed PHP 8.4 compatibility issues across 9 files:

  • src/App/Helpers/app.php - Fixed stop() function nullable parameters
  • src/App/Helpers/dir.php - Fixed modules_dir() function nullable parameters
  • src/Http/Traits/Request/Body.php - Fixed get() method nullable parameter
  • src/Http/Traits/Response/Body.php - Fixed get() method nullable parameter
  • src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php - Fixed constructor nullable parameter
  • src/Libraries/Database/Adapters/Idiorm/Statements/Criteria.php - Fixed nullable parameters
  • src/Libraries/Database/Adapters/Idiorm/Statements/Join.php - Fixed nullable parameters
  • src/Libraries/Session/Adapters/Database/DatabaseHandler.php - Fixed return type compatibility
  • src/Libraries/Auth/Traits/AuthTrait.php - Fixed nullable parameters

Why

PHP 8.4 introduced stricter type checking that caused fatal errors and deprecated warnings throughout the framework.

How to test

Run the existing test suite, all tests should pass with PHP 8.4.

Backward compatibility

These changes maintain full backward compatibility with PHP 7.3+.

References

https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated
https://www.php.net/manual/en/sessionhandlerinterface.gc.php

If you need me to make any changes or adjustments to this PR, please let me know!

@Wiltzsu

Wiltzsu commented Oct 20, 2025

Copy link
Copy Markdown
Collaborator Author

Fixed the type compatibility issue in the gc() method. The problem was that deleteMany() returns bool, but SessionHandlerInterface::gc() requires int|false.

The fix:

  • Store the deleteMany() result in a variable
  • Return false on failure, (int)$deleted on success (converts true to 1)

Scrutinizer strangely gives contradictory error messages about the expected return type. The fix follows the official PHP SessionHandlerInterface specification which requires int|false.

Comment thread src/Libraries/Session/Adapters/Database/DatabaseHandler.php Outdated

@armanist armanist left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @Wiltzsu, thanks for contributing to Quantum PHP Framework 🙌,

The nullable parameter changes look great. However, there’s an issue with the return type of the DatabaseHandler::gc() method.

Since QF still supports PHP 7.3 (support will be dropped starting from version 3.0) and PHP 7.4, we can’t use union types yet.
Scrutinizer runs with PHP 7.4, which is why it flagged the incompatibility.

Could you please adjust the return type accordingly?

@armanist armanist added the enhancement New feature or request label Oct 21, 2025
@armanist armanist added this to the 2.9.9 milestone Oct 21, 2025
@armanist
armanist merged commit 04b6934 into quantum-php:master Oct 21, 2025
3 checks passed
@Wiltzsu

Wiltzsu commented Oct 21, 2025

Copy link
Copy Markdown
Collaborator Author

Hi @armanist,

I reverted the gc() method to use bool return type and added the #[\ReturnTypeWillChange].

Thanks for letting me contribute!

@armanist

Copy link
Copy Markdown
Collaborator

Hi @armanist,

I reverted the gc() method to use bool return type and added the #[\ReturnTypeWillChange].

Thanks for letting me contribute!

You're welcome @Wiltzsu, yes I saw the attribute you've added, although it's PHP 8+ feature but it didn't failed on running version 7.4 so we kept it.

If you are interested to contribute more feel free to check the existing issues

@Wiltzsu

Wiltzsu commented Oct 21, 2025

Copy link
Copy Markdown
Collaborator Author

Sure, I'll have a look 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants