Skip to content
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

Remove constructs that deprecate with PHP 8.4 #75

Merged
merged 2 commits into from
Jul 24, 2024

Conversation

MarkusBauer
Copy link
Contributor

PHP 8.4 deprecates type declarations of the form function x(string $y = null) - see longer explanation here. PHP 9 will no longer support such implicit nullable parameters.
This PR fixes this pattern everywhere.

How to reproduce: run a syntax check with PHP 8.4:
find . -type f \( -name "*.php" -o -name "*.ctp" \) -exec php -d error_reporting=32765 -l {} \; | grep -v 'No syntax errors detected'
Result before this PR:

PHP 8.4.0alpha2 (cli) (built: Jul 19 2024 19:23:28) (NTS)
Deprecated: ControllerAuthorize::controller(): Implicitly marking parameter $controller as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Controller/Component/Auth/ControllerAuthorize.php on line 46
Deprecated: BaseAuthorize::controller(): Implicitly marking parameter $controller as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Controller/Component/Auth/BaseAuthorize.php on line 92
Deprecated: SecurityComponent::blackHole(): Implicitly marking parameter $exception as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Controller/Component/SecurityComponent.php on line 347
Deprecated: AuthComponent::isAuthorized(): Implicitly marking parameter $request as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Controller/Component/AuthComponent.php on line 456
Deprecated: PrivateActionException::__construct(): Implicitly marking parameter $previous as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Error/exceptions.php on line 300
Deprecated: DboSource::lastError(): Implicitly marking parameter $query as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 530
Deprecated: DboSource::conditions(): Implicitly marking parameter $Model as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 2764
Deprecated: DboSource::conditionKeysToString(): Implicitly marking parameter $Model as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 2807
Deprecated: DboSource::_parseKey(): Implicitly marking parameter $Model as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 2912
Deprecated: DboSource::order(): Implicitly marking parameter $Model as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 3086
Deprecated: DboSource::group(): Implicitly marking parameter $Model as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 3169
Deprecated: DboSource::having(): Implicitly marking parameter $Model as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Datasource/DboSource.php on line 3199
Deprecated: Model::validator(): Implicitly marking parameter $instance as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/Model/Model.php on line 3916
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /app/lib/Cake/Console/Command/Task/FixtureTask.php on line 251
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /app/lib/Cake/Console/Command/Task/FixtureTask.php on line 251
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /app/lib/Cake/Console/Command/Task/ModelTask.php on line 173
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /app/lib/Cake/Console/Command/Task/ModelTask.php on line 904
Deprecated: Using ${var} in strings is deprecated, use {$var} instead in /app/lib/Cake/Test/Case/Console/ShellTest.php on line 610
Deprecated: XmlView::__construct(): Implicitly marking parameter $controller as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/View/XmlView.php on line 68
Deprecated: JsonView::__construct(): Implicitly marking parameter $controller as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/View/JsonView.php on line 68
Deprecated: View::__construct(): Implicitly marking parameter $controller as nullable is deprecated, the explicit nullable type must be used instead in /app/lib/Cake/View/View.php on line 333

With this PR, the upcoming syntax errors are fixed.

@@ -344,7 +344,7 @@ public function requireAuth() {
* @link https://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#handling-blackhole-callbacks
* @throws BadRequestException
*/
public function blackHole(Controller $controller, $error = '', SecurityException $exception = null) {
public function blackHole(?Controller $controller, $error = '', ?SecurityException $exception = null) {
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't we keep Controller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, $controller is not optional, my bad. Thank you!
(and I also corrected a typo that I just spotted)

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for fix 🙌

@kamilwylegala
Copy link
Owner

Thank you for your contribution. I left one comment.

@kamilwylegala
Copy link
Owner

Looks good, thanks one more time for your contribution. Merging 😊

@kamilwylegala kamilwylegala merged commit 2220f35 into kamilwylegala:master Jul 24, 2024
5 checks passed
@MarkusBauer MarkusBauer deleted the fix-deprecations branch July 25, 2024 07:01
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