Problem/Motivation
As per #1158720-69: Improve text for parameter type hinting in function declaration this issue proposes that all new Drupal 9 code should use scalar typehints and return typehints since our minimum PHP version is 7.3.
This is only for new code to avoid BC implications. We will work out how to change existing code (probably in Drupal 10) in #3050720: [Meta] Implement strict typing in existing code.
The related Coding Standards issue explains that there is an existing policy for using strict type hints. See comment #17 for the details.
Proposed resolution
New methods and functions added in Drupal 9 should use scalar typehints and return typehints.
Example (pseudo-code):
public function checkAccess(string $permission): AccessResult {
$access_result = AccessResult::allowedIfHasPermission($this->user, $permission);
return $access_result;
}
Post something on groups.drupal.org/core
Remaining tasks
Add examples to Parameter and return typehinting
Draft and publish a change record that links that coding standards section.
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/a