-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Description
Background
PR #57343 was recently closed, which aimed to add missing PHP return type declarations to various Laravel framework classes. The PR included improvements to type safety and developer experience by adding explicit return type declarations to methods that had docblock types but were missing PHP return types.
Affected Areas
The PR addressed missing return type declarations in:
Session Classes
EncryptedStore::getEncrypter(): EncrypterContract
CacheBasedSessionHandler::getCache(): CacheContract
SessionManager
methods:shouldBlock(): bool
,blockDriver(): ?string
, etc.
Config Classes
Repository
methods:has(): bool
,get(): mixed
,getMany(): array
, etc.
Console Classes
PruneStaleTagsCommand::getArguments(): array
ConfigMakeCommand::promptForMissingArgumentsUsing(): array
ConfigCacheCommand::handle(): void
Benefits of Adding Return Types
- Enhanced Type Safety: Explicit return types catch type-related errors at compile time
- Better IDE Support: Improved autocompletion and static analysis
- Developer Experience: Clearer method contracts and better documentation
- Modern PHP Standards: Aligns with PHP 8.2+ best practices
- Backward Compatibility: All proposed changes were fully backward compatible
Questions for Discussion
-
Policy Clarification: Is there a specific policy or guideline regarding when to add return type declarations to existing methods?
-
Incremental Approach: Would a more targeted approach be preferred (e.g., focusing on one subsystem at a time)?
-
Breaking Changes Concern: Are there concerns about potential breaking changes, even though return type declarations are generally backward compatible?
-
Timing: Is this type of improvement better suited for major version releases?
-
Community Input: Should this type of enhancement go through an RFC process or community discussion first?
Proposed Next Steps
- Clarify the framework's stance on adding return type declarations to existing methods
- Determine if there are specific guidelines or criteria for such improvements
- Consider whether a more focused or phased approach would be more appropriate
- Gather community feedback on the value and timing of such improvements
Related
- Closed PR: [12.x] Add missing PHP return type declarations to Session, Config, and Console classes #57343
- This discussion aims to understand the reasoning behind the closure and explore potential paths forward for improving type safety in the Laravel framework.
Note: This issue is created to foster discussion and understanding, not to challenge the maintainers' decision. The goal is to learn and potentially find alternative approaches that align with the project's direction.