'In PHP 8.1, is there a more concise way to define the variable type than using @var?
Suppose I have the following line of code in a test (this is from Laravel)
$eyepieceLine = EyepieceLine::factory()->create();
The factory()->create() is a Laravel internal thing and I cannot control the return type of create().
However, the thing it returns adheres to an interface and I only care about the interface for the purpose of the rest of the test.
What I currently need to do is this:
/** @var EyepieceLineInterface $eyepieceLine */
$eyepieceLine = EyepieceLine::factory()->create();
This is quite verbose, ugly, and takes up more space than it should (imagine several such lines of code for different entities).
Does PHP have the ability to type hint in-line, like other languages?
E.g:
EyepieceLineInterface $eyepieceLine = EyepieceLine::factory()->create();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
