Enable existing interfaces to add return type hints with a deprecation message for implementors

Created on 16 January 2023, over 1 year ago
Updated 30 August 2024, 17 days ago

Problem/Motivation

Split from 🌱 [Meta] Implement strict typing in existing code Active .

PHP allows child classes to add return type hints in the parent class doesn't. This means we can add return type hints to interfaces in Drupal 11, contrib modules can add them whenever, and those modules will continue to work in both Drupal 10 and 11.

What we can't do, is notify contrib modules that they need to add the type hint to continue to work.

Symfony has partially solved this issue - it looks at @return phpdoc, and if there's no matching type hint, the debug classloader issues a deprecation message. However, this is overkill - it issues deprecations for classes even where the new version doesn't have a return type hint, so can be misleading (and noisy).

Steps to reproduce

Proposed resolution

We want something similar to Symfony's implementation, but explict instead of implicit. For example, could we add an attribute like [#ReturnTypeHintDeprecation]. To do this would require overriding Symfony's debug classloader though.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component
Base 

Last updated about 1 hour ago

Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024