Magic properties: original on entities, name on UserSession and password on User are not reported as deprecated
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- php
- Domain
- testing-qa
Research direction
Start by reading EntityFieldReflection and its isDeprecated() and getDeprecatedDescription() methods; the issue identifies these as the failing entry points. Check how deprecations are handled for magic properties and ignored inside DeprecationHelper::backwardsCompatibleCall() callbacks. Done means the three listed properties report Drupal’s deprecation messages while callback uses remain ignored; an open linked pull request (#1076) is already working on this issue.
Written by the indexing model from the issue text.
Description
Summary
Drupal 11.2 deprecated the magic original property of entities. It is removed from Drupal 12. EntityBase::__get(), __set(), __isset() and __unset() trigger, for example:
Getting the original property is deprecated in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::getOriginal() instead. See https://www.drupal.org/node/3295826
In phpstan-drupal EntityFieldReflection gives original a type, but its isDeprecated() always returns no. So phpstan-drupal and the deprecation rules report nothing, and Upgrade Status, which uses them, doesn't either.
Steps to reproduce
On Drupal 11.5.x-dev, with PHPStan 2.3.5, phpstan-drupal 2.2.2 (the code is the same in 2.3.0) and phpstan-deprecation-rules, at level 2:
<?php
declare(strict_types=1);
namespace Drupal\pst_probe;
use Drupal\node\NodeInterface;
final class Probe {
public function check(NodeInterface $node): ?string {
if (isset($node->original)) {
return $node->original->label();
}
return $node->getOriginal()?->label();
}
}
Result: [OK] No errors.
Expected: lines 12 and 13 are reported as uses of a deprecated property, with core's message.
How often this happens
In unpatched copies of 75 contributed modules and themes from the Drupal CMS stack, ->original is used without DeprecationHelper in webform (7 places), crop, key, ai and search_api. These break on Drupal 12.
Proposed resolution
In EntityFieldReflection, when the property name is original and EntityInterface has a getOriginal() method (Drupal 11.2 and later):
isDeprecated()should return yes.getDeprecatedDescription()should return core's text: "in drupal:11.2.0 and is removed from drupal:12.0.0. Use \Drupal\Core\Entity\EntityInterface::getOriginal() instead. See https://www.drupal.org/node/3295826".
Uses inside DeprecationHelper::backwardsCompatibleCall() callbacks should still be ignored, like other deprecations.
Two more magic properties have the same problem. They need to be handled the same way:
UserSession::$name, deprecated in drupal:11.3.0 and removed from drupal:12.0.0. UsegetAccountName().User::$password, deprecated in drupal:11.4.0 and removed from drupal:12.0.0. See https://www.drupal.org/node/3569185.
LLM disclosure
LLM was used to find and resolve this issue. With human review.
- Dominant language
- PHP
- Stars
- 208
- Forks
- 88
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 15
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mglaman/phpstan-drupal
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
mglaman/phpstan-drupal#1078 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
mglaman/phpstan-drupal#1079 ·
Maintainers usually reply within 1 day
-
Report constraint plugins that break on Drupal 12 because they have no named-arguments constructorPossibly taken @goba claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
mglaman/phpstan-drupal#1075 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 25/100
mglaman/phpstan-drupal#1051 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
mglaman/phpstan-drupal#1047 ·
Maintainers usually reply within 1 day
All issues in mglaman/phpstan-drupal
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getgrav/grav-plugin-sitemap#125 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
nikic/PHP-Parser#1184 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
api-platform/core#8835 ·
Maintainers usually reply within 2 days
-
14.3.x
Difficulty 1/5 1-3 hours Newbie friendliness 82/100