Repository navigation
Fix: PHP 8.4 compatibility issues for nullable parameters and return types - #335
Conversation
|
Fixed the type compatibility issue in the The fix:
Scrutinizer strangely gives contradictory error messages about the expected return type. The fix follows the official PHP |
armanist
left a comment
There was a problem hiding this comment.
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?
…ttribute for PHP version compatibility
|
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 |
|
Sure, I'll have a look 👍 |
What was changed
Fixed PHP 8.4 compatibility issues across 9 files:
src/App/Helpers/app.php- Fixedstop()function nullable parameterssrc/App/Helpers/dir.php- Fixedmodules_dir()function nullable parameterssrc/Http/Traits/Request/Body.php- Fixedget()method nullable parametersrc/Http/Traits/Response/Body.php- Fixedget()method nullable parametersrc/Libraries/Database/Adapters/Idiorm/IdiormDbal.php- Fixed constructor nullable parametersrc/Libraries/Database/Adapters/Idiorm/Statements/Criteria.php- Fixed nullable parameterssrc/Libraries/Database/Adapters/Idiorm/Statements/Join.php- Fixed nullable parameterssrc/Libraries/Session/Adapters/Database/DatabaseHandler.php- Fixed return type compatibilitysrc/Libraries/Auth/Traits/AuthTrait.php- Fixed nullable parametersWhy
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!