This is nice, but I have two problems with it (and for those who are wondering) - This is only useful for static analysis and documentation. 1) PHP Runtime has no idea of your template rules :( 2) You will have to implement a bunch of if statements in your production code to manually type and value check the arguments (something you get for free with static typing) . Adds a lot of unnecessary code Not yet convinced this is the way in PHP (Or JavaScript for that matter!!) Am I missing something?
This is convential in many other languages (Rust, Scala, Kotlin, Java, C#, F#, Haskell just to name the ones I know of). I think the main reason is that all of them have generics as first class syntax where it goes into the same line as the function definition. Since PHP does not have it and we need annotations, we have the "freedom" to name our types as long as we want.
Nuno this is fire. Please, please more content like this PHPStan makes coding so much better.
just one word: GREAT ... generics perfectly explained. tnx u so much
For personal project its if its an array, else . Outside of that, I follow whatever convention my company follows. Usually
@@fathularifkamarudin55 makes sense!
Finally, I discovered how those @template work. You explained well
Please do more videos on Generics
People name their variables like it costs ink to print them on the screen.
ahah
This is nice, but I have two problems with it (and for those who are wondering) - This is only useful for static analysis and documentation.
1) PHP Runtime has no idea of your template rules :(
2) You will have to implement a bunch of if statements in your production code to manually type and value check the arguments (something you get for free with static typing) . Adds a lot of unnecessary code
Not yet convinced this is the way in PHP (Or JavaScript for that matter!!)
Am I missing something?
Still better than nothing.
bro has that cartoon "surprised" lip quirk
I prefer one letter generic type, like T or K
Interesting!
This is convential in many other languages (Rust, Scala, Kotlin, Java, C#, F#, Haskell just to name the ones I know of).
I think the main reason is that all of them have generics as first class syntax where it goes into the same line as the function definition.
Since PHP does not have it and we need annotations, we have the "freedom" to name our types as long as we want.
@@holonaut exactly, this habit comes from Java. Also following same rules for TypeScript projects as well.