Laravel 10 will use native PHP type declarations across any generated code that can exist in userland:
Laravel 10.x (release in Feb 2023) will add type-hints and return types to all application skeleton methods. ✅
Property types are not being added due to that being a breaking change.
— Taylor Otwell 🪐 (@taylorotwell) November 14, 2022
Types are being added in a way that brings the latest PHP type-hinting features to Laravel projects without breaking backward compatibility at the framework level:
- Return types
- Method arguments
- Redundant annotations are removed where possible
- Allow user land types in closure arguments
- Does not include typed properties
As an example, if a skeleton method has a return type of
array, an annotation might exist to provide better type clarity when not possible through native types:
2 * Get the host patterns that should be trusted.
4 * @return array<int, string>
6public function hosts(): array
8 return [
In the above example, IDEs will know the shape of the array, which is helpful information not possible in PHP’s native typing design.
Further, all code generated by the framework will follow the same type-hint guidelines above, meaning that as you create files with
make commands, they will include native type hinting in the same way described above.
When will Laravel 10 be released?
According to the Support Policy docs, Laravel 10 will be released on February 7th, 2023.
Given the size of the Laravel ecosystem, this is a significant undertaking, and we applaud Laravel for keeping backward compatibility a priority.