PHP Anonymous Classes - Full PHP 8 Tutorial

  Рет қаралды 16,817

Program With Gio

Program With Gio

Күн бұрын

Пікірлер: 33
@ryanqvincent144
@ryanqvincent144 Жыл бұрын
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
@ProgramWithGio Жыл бұрын
Super happy to hear this & glad it was useful. Thank you 💙
@parijke
@parijke 3 жыл бұрын
I was about to ask for the use cases, as they were discussed at the end. Very nice
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
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.
@Zubbee
@Zubbee 2 жыл бұрын
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.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Awesome 👍. You're welcome & thank you 🙌
@Vitalii-m6r
@Vitalii-m6r Жыл бұрын
Anonymous classes are essential for tests. Thanks a million!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
They do come in handy for sure
@federicobau8651
@federicobau8651 2 жыл бұрын
Great video did not know about anonymous classes
@shlxng1787
@shlxng1787 Жыл бұрын
Perfect explanation as always 👏
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you
@hossamragab1428
@hossamragab1428 9 ай бұрын
you know that u are the best right !!
@ProgramWithGio
@ProgramWithGio 9 ай бұрын
Thank you 💙
@ItsDigiUtime
@ItsDigiUtime Жыл бұрын
Kind of mind blown by the use of anonymous classes in testing.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
They do come in handy
@ilya_123__
@ilya_123__ Жыл бұрын
thank you for this lesson
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You are welcome!
@adrianez-programuj3313
@adrianez-programuj3313 3 жыл бұрын
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.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
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
@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.
@karam0101
@karam0101 2 жыл бұрын
Thank you very much, great video as usual
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome, thank you
@aerohcss
@aerohcss 2 ай бұрын
Gio, how do you insert "public" to 3 parameters in __construct simultaneously? What PHPStorm shortcut it is?
@ProgramWithGio
@ProgramWithGio 2 ай бұрын
Its multicursor editing, alt + shift + click. Should work in most code editors
@aerohcss
@aerohcss 2 ай бұрын
@@ProgramWithGio Thank you, teacher
@memack101
@memack101 2 жыл бұрын
Thank you.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
💙
@Probablyaliq4
@Probablyaliq4 2 ай бұрын
Thnak you
@ProgramWithGio
@ProgramWithGio 2 ай бұрын
You're welcome
@sym2574
@sym2574 Жыл бұрын
👍👍👍👍👍👍👍👍👍
@ProgramWithGio
@ProgramWithGio Жыл бұрын
🙏🙏
@mohammadkhazaee9730
@mohammadkhazaee9730 3 жыл бұрын
Anonymous classes just support in php v8.* ?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
No, anonymous classes was added in PHP 7
PHP Traits - How They Work & Drawbacks - Full PHP 8 Tutorial
31:41
Program With Gio
Рет қаралды 33 М.
Players push long pins through a cardboard box attempting to pop the balloon!
00:31
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 51 МЛН
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 6 МЛН
Java Anonymous Inner Classes Explained in 6 Minutes
6:27
Coding with John
Рет қаралды 101 М.
When to use Traits, Interfaces, and Abstract Classes in PHP
15:08
Andrew Schmelyun
Рет қаралды 23 М.
Why Favor Object Composition Over Class Inheritance? A Deep Dive
19:00
PHP Serialize Objects & Serialize Magic Methods - Full PHP 8 Tutorial
11:47
PHP Interfaces & Polymorphism - Object Oriented PHP Tutorial
8:19
Clever Techie
Рет қаралды 12 М.
Players push long pins through a cardboard box attempting to pop the balloon!
00:31