Laravel0Laravel 10 Application Skeleton Code Will Have Native Type Declarations

[ad_1]

Laravel 10 will use native PHP type declarations across any generated code that can exist in userland:

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:

1/**

2 * Get the host patterns that should be trusted.

3 *

4 * @return array<int, string>

5 */

6public function hosts(): array

7{

8 return [

9 'laravel.test',

10 ];

11}

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.



[ad_2]

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *