Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Jaypan on
Recently I've finally begun shifting my focus from D7 to D8, and I'm converting a site over to D8. In D7, I type-hinted my account objects as \stdClass, since they were not members of any class. However in D8, they are now members of the User class.
That said, I'm finding in some code on the net that people are typehinting as Drupal\Core\Session\AccountInterface
, and in other places as Drupal\user\UserInterface
. How should we be determining which one to use for our typehints, and what is the difference between the two types of objects?