Laravel 10 will use native PHP kind declarations throughout any generated code that may exist in userland:
Laravel 10.x (launch in Feb 2023) will add type-hints and return varieties to all utility skeleton strategies. ✅
Property varieties aren’t being added as a result of that being a breaking change.
— Taylor Otwell 🪐 (@taylorotwell) November 14, 2022
Sorts are being added in a method that brings the most recent PHP type-hinting options to Laravel initiatives with out breaking backward compatibility on the framework degree:
- Return varieties
- Technique arguments
- Redundant annotations are eliminated the place attainable
- Enable person land varieties in closure arguments
- Doesn’t embrace typed properties
For example, if a skeleton methodology has a return kind of
array, an annotation would possibly exist to offer higher kind readability when not attainable by native varieties:
2 * Get the host patterns that ought to be trusted.
4 * @return array<int, string>
6public perform hosts(): array
8 return [
Within the above instance, IDEs will know the form of the array, which is useful data not attainable in PHP’s native typing design.
Additional, all code generated by the framework will observe the identical type-hint tips above, that means that as you create information with
make instructions, they’ll embrace native kind hinting in the identical method described above.
When will Laravel 10 be launched?
In line with the Assist Coverage docs, Laravel 10 will likely be launched on February seventh, 2023.
Given the scale of the Laravel ecosystem, it is a important endeavor, and we applaud Laravel for preserving backward compatibility a precedence.