Advanced PHP: Generics Explained

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.พ. 2025

ความคิดเห็น • 15

  • @lukmauu
    @lukmauu 18 วันที่ผ่านมา +6

    Nuno this is fire. Please, please more content like this PHPStan makes coding so much better.

  • @coscisimone
    @coscisimone 5 วันที่ผ่านมา +1

    just one word: GREAT ... generics perfectly explained. tnx u so much

  • @fathularifkamarudin55
    @fathularifkamarudin55 18 วันที่ผ่านมา +5

    For personal project its if its an array, else . Outside of that, I follow whatever convention my company follows. Usually

    • @nunomaduro
      @nunomaduro  18 วันที่ผ่านมา

      @@fathularifkamarudin55 makes sense!

  • @Pozza94
    @Pozza94 17 วันที่ผ่านมา +2

    Finally, I discovered how those @template work. You explained well

  • @HugoAvila
    @HugoAvila 18 วันที่ผ่านมา +3

    Please do more videos on Generics

  • @JonnyJKF
    @JonnyJKF 18 วันที่ผ่านมา +7

    People name their variables like it costs ink to print them on the screen.

    • @nunomaduro
      @nunomaduro  18 วันที่ผ่านมา +2

      ahah

  • @mmasa1
    @mmasa1 18 วันที่ผ่านมา +1

    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?

    • @ivanjelenic5627
      @ivanjelenic5627 16 วันที่ผ่านมา +1

      Still better than nothing.

  • @thebirdhasbeencharged
    @thebirdhasbeencharged 18 วันที่ผ่านมา +1

    bro has that cartoon "surprised" lip quirk

  • @valehasadli
    @valehasadli 18 วันที่ผ่านมา +4

    I prefer one letter generic type, like T or K

    • @nunomaduro
      @nunomaduro  18 วันที่ผ่านมา

      Interesting!

    • @holonaut
      @holonaut 18 วันที่ผ่านมา

      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.

    • @valehasadli
      @valehasadli 18 วันที่ผ่านมา

      @@holonaut exactly, this habit comes from Java. Also following same rules for TypeScript projects as well.