Skip to content

Fix PHP 8.2 warning: Use [static::class, '…'] instead of 'static::… for callbacks#570

Merged
localheinz merged 7 commits intoFakerPHP:mainfrom
MyIgel:php-8.2
Dec 13, 2022
Merged

Fix PHP 8.2 warning: Use [static::class, '…'] instead of 'static::… for callbacks#570
localheinz merged 7 commits intoFakerPHP:mainfrom
MyIgel:php-8.2

Conversation

@MyIgel
Copy link
Copy Markdown

@MyIgel MyIgel commented Dec 10, 2022

What is the reason for this PR?

This implements remaining changes for #479 (Use of "static" in callables is deprecated in PHP 8.2) and is an extension of #528 (Ensure php 8.2 compatibility)

Author's checklist

Summary of changes

Use self::class . '::[…]' instead of 'static::[…]' on callbacks which triggered a PHP 8.2 warning. Implementation analogous to php.watch.

The phpstan "errors" can be ignored as that functionality still works for PHP 7.4 and is thus added to ignoreErrors.

Review checklist

  • All checks have passed
  • Changes are approved by maintainer

@MyIgel
Copy link
Copy Markdown
Author

MyIgel commented Dec 10, 2022

I guess the BC Check / Roave BC Check can be ignored? :D

@localheinz
Copy link
Copy Markdown
Member

@MyIgel

Yes, we are waiting for someone (perhaps @Nyholm) to fix this issue.

Copy link
Copy Markdown
Member

@localheinz localheinz left a comment

Choose a reason for hiding this comment

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

Can you also apply this diff?

diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 1c521356..37222a4f 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -13,7 +13,7 @@
         <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
     </listeners>
     <php>
-        <env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=404"/>
+        <env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
     </php>
     <testsuites>
         <testsuite name="Faker Test Suite">

@localheinz localheinz linked an issue Dec 10, 2022 that may be closed by this pull request
@localheinz localheinz mentioned this pull request Dec 10, 2022
5 tasks
@localheinz localheinz added the bug Something isn't working label Dec 10, 2022
}

private static function replaceWildcard($string, $wildcard = '#', $callback = 'static::randomDigit')
private static function replaceWildcard($string, $wildcard, $callback)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Method is private and always invoked with arguments for all parameters - no need for default values.

Also see #571.

@localheinz localheinz changed the title Fix PHP 8.2 warning: Use self::class . '::[…]' instead of 'static::[…]' for callbacks Fix PHP 8.2 warning: Use [static::class, '…'] instead of 'static::… for callbacks Dec 10, 2022
@MyIgel
Copy link
Copy Markdown
Author

MyIgel commented Dec 10, 2022

I guess the changes should be squashed on merge?

@localheinz
Copy link
Copy Markdown
Member

Thank you, @GrahamCampbell and @MyIgel!

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use of "static" in callables is deprecated in PHP 8.2

3 participants