Problem/Motivation
In scope of PHP8.1 compatibility static analysis it was discovered some deprecations in Drupal Core codebase:
1. 60 docroot/core/lib/Drupal/Core/Installer/NormalInstallerServiceProvider.php get_called_class() without argument
2. 33, 50 docroot/core/lib/Drupal/Core/Render/Element/StatusMessages.php get_class() without argument
3. 88 docroot/core/modules/system/src/Plugin/Block/SystemMenuBlock.php get_class() without argument
4. 780 docroot/core/lib/Drupal/Core/Url.php get_class() without argument
Proposed resolution
According to https://wiki.php.net/rfc/deprecations_php_8_1 remove argument-less get_class() and get_called_class() usage in favor of the dedicated self::class, parent::class and static::class syntax.
| Comment | File | Size | Author |
|---|
Issue fork drupal-3351004
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
Natallia commentedComment #3
vishal choudharyRelated to -> 4. 780 docroot/core/lib/Drupal/Core/Url.php get_class() without argument.
Example:
If you want to get the class name of the current object, you need to replace the following code:
1. get_class();
Should be replaced with
2. get_called_class();
Should be Replaced with
Comment #4
anchal_gupta commentedI have uploaded the patch.
Addressed #3
Please review it.
Comment #5
anchal_gupta commentedComment #7
Natallia commentedAs It is implies that functionality of code will not be touched:
The changes 1. get_class() -> get_class($this) and 2. get_called_class() -> get_called_class(self::class) are both not equivalent (e.g. see Example2 from https://www.php.net/manual/en/function.get-class.php)
and the changes in the merge request are taken from proposal here https://wiki.php.net/rfc/deprecations_php_8_1
Comment #8
smustgrave commentedRemoving credit for #4 as it's expected to test your path before uploading.
Reviewing MR 3741
Searched for get_class() found 5 instances that were covered
Searched for get_called_class() found 1 that was covered
Searched for get_parent_class and found 0
Looks good
Good work!
Comment #12
catchCommitted/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!
Comment #13
andypost