I came to this video because I have a need for local classes but I don't need the full 'class file' etc. This was exactly as I needed! It is explained really well and shows the advantages and limitations clearly. An excellent 8 minutes spent! Thank you. Appreciated. :) p.s. My 'use case' is that I have an array and I need to add a couple of functions to easily use the values of the array in testing. Anonymous classes are the perfect answer for this. :)
@ProgramWithGio Жыл бұрын
Super happy to hear this & glad it was useful. Thank you 💙
@parijke3 жыл бұрын
I was about to ask for the use cases, as they were discussed at the end. Very nice
@ProgramWithGio3 жыл бұрын
Yup, for me, the main use case has been with testing. Haven't really used it outside of that. But I've seen frameworks use anonymous classes outside of testing for example Laravel recently added anonymous classes support for its migrations.
@Zubbee2 жыл бұрын
I struggled with wrapping my head around Anonymous Functions so you can imagine how I felt when I reached this topic. But it was easier to understand this time. Plus the use case you talked about helped to put things in place in my mind. Thanks Gio.
@ProgramWithGio2 жыл бұрын
Awesome 👍. You're welcome & thank you 🙌
@Vitalii-m6r Жыл бұрын
Anonymous classes are essential for tests. Thanks a million!
@ProgramWithGio Жыл бұрын
They do come in handy for sure
@federicobau86512 жыл бұрын
Great video did not know about anonymous classes
@shlxng1787 Жыл бұрын
Perfect explanation as always 👏
@ProgramWithGio Жыл бұрын
Thank you
@hossamragab14289 ай бұрын
you know that u are the best right !!
@ProgramWithGio9 ай бұрын
Thank you 💙
@ItsDigiUtime Жыл бұрын
Kind of mind blown by the use of anonymous classes in testing.
@ProgramWithGio Жыл бұрын
They do come in handy
@ilya_123__ Жыл бұрын
thank you for this lesson
@ProgramWithGio Жыл бұрын
You are welcome!
@adrianez-programuj33133 жыл бұрын
Can you explain why did you use promoted properties in both constructors? I think it should be used only in parent constructor for clarity that you are not creating the same properties in Child Class.
@ProgramWithGio3 жыл бұрын
Thank you for pointing it out & yes you are correct. I made a mistake while copying & pasting the parent's constructor arguments, there is no need to use property promotion inside the anonymous class when extending from a base class, simply accepting those as arguments is enough. That being said, the example right after that does not use inheritance would need the properties defined since we are passing down the arguments.
@amijazz1941 Жыл бұрын
@@ProgramWithGio If I don't use parent's constructor arguments in the constructor of anonymous class then I get an error that: Fatal error: Uncaught ArgumentCountError: Too few arguments to functionApp\AnonymousClassA::__construct(), 0 passed in /var/www/app/AnonymousClassA.php on line 23 and exactly 2 expected in /var/www/app/AnonymousClassA.php:7 Stack trace: #0 /var/www/app/AnonymousClassA.php(23): App\AnonymousClassA->__construct() #1 /var/www/app/AnonymousClassA.php(19): App\AnonymousClassA@anonymous->__construct(1, 2) #2 /var/www/public/index.php(10): App\AnonymousClassA->bar() AnonymousClassA is name of my parent class.
@karam01012 жыл бұрын
Thank you very much, great video as usual
@ProgramWithGio2 жыл бұрын
You're welcome, thank you
@aerohcss2 ай бұрын
Gio, how do you insert "public" to 3 parameters in __construct simultaneously? What PHPStorm shortcut it is?
@ProgramWithGio2 ай бұрын
Its multicursor editing, alt + shift + click. Should work in most code editors