PHP Iterators & Iterable Type - Iterate Over Objects - Full PHP 8 Tutorial

  Рет қаралды 25,183

Program With Gio

Program With Gio

Күн бұрын

Пікірлер: 83
@ousssika5359
@ousssika5359 11 ай бұрын
i have been using youtube for 15 years to study , hands down your the best teacher , tha a man can hope for
@ProgramWithGio
@ProgramWithGio 10 ай бұрын
Thank you 💙
@only_visiting
@only_visiting 5 ай бұрын
Agreed 100%!
@lynic-0091
@lynic-0091 Жыл бұрын
Jaw drop, I had no friggin clue something like this was possible. This is the best PHP course I've ever seen.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you 🙏
@Vitalii-m6r
@Vitalii-m6r Жыл бұрын
Hands down, this is the best explanation of Iterators I've even seen. Thanks!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Happy to hear, thank you 💙
@karam0101
@karam0101 2 жыл бұрын
Every time I see the number of subscribers increased I feel really happy, cause I hope every body watches this series in which you're making programming more exciting and more fun! thank you
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you 💙💙
@muhammadaafaq482
@muhammadaafaq482 2 жыл бұрын
I'm really enjoying this series and learning more Respect from Pakistan.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Glad to hear that, thank you 💙💙
@federicobau8651
@federicobau8651 2 жыл бұрын
Extremely simple explanation
@KochADV
@KochADV 9 сағат бұрын
great lesson. thanks
@khusamalfas2121
@khusamalfas2121 3 жыл бұрын
This the best class about iterators with examples. Keep it up will done.
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
Thank you
@FranciscoJunior29
@FranciscoJunior29 2 жыл бұрын
Thank you so much for sharing this content of excellent quality.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome 🙌
@ilya_123__
@ilya_123__ 11 ай бұрын
Thank you for this lesson!
@ProgramWithGio
@ProgramWithGio 11 ай бұрын
You're welcome
@emekatimothyiloba699
@emekatimothyiloba699 Жыл бұрын
Thank you Gio
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@Haamome
@Haamome 2 жыл бұрын
i love you bro thank you so much for all those videos clear and simple example that make it easy.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Glad you like them, thank you 💙💙
@Armando-px8hi
@Armando-px8hi Жыл бұрын
Thank you GIO:)
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You're welcome
@Zubbee
@Zubbee 2 жыл бұрын
Great lesson, I've bagged another one (need to practice though). Thanks alot Gio.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Awesome, thank you 💙 keep going
@aleksandrkanygin2672
@aleksandrkanygin2672 2 жыл бұрын
Great lesson, thank you!
@neriusshaqiri1514
@neriusshaqiri1514 2 жыл бұрын
Thank you for tor sharing this, great video!
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Glad you enjoyed it, thank you 💙
@omaryahia
@omaryahia Жыл бұрын
amazing 🌟
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Thank you! 😊
@derzskyi1
@derzskyi1 2 жыл бұрын
Thank you! "Invoice" inside "InvoiceList" iterable must have public properties, but what if I don't want to expose the internal state of that object. What are the options for this?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
In PHP 8.1 you can make properties read-only, that way you can have public property accessible but can't be changed. You can also just make them private/protected and create appropriate getter/setters.
@benderbg
@benderbg 3 ай бұрын
Thanks!
@ProgramWithGio
@ProgramWithGio 3 ай бұрын
No problem!
@ינוןאלבז-כ1ז
@ינוןאלבז-כ1ז Жыл бұрын
I dont know any of that topic. Thanks!!!!!!
@ProgramWithGio
@ProgramWithGio Жыл бұрын
🙌🙌
@abdallahdamra5602
@abdallahdamra5602 Жыл бұрын
instead of implementing iterator, why not just use nested foreach loop? or you just did it to show the implementation of iterator?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
It depends on the data structure of what you are iterating over. If its just simple arrays then yea sure you should just use foreach loop on the array, if its a complex data structure or you need more control over how its iterated over then you implement iterator.
@memack101
@memack101 2 жыл бұрын
Thank you.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
You're welcome 👍
@diarqoroviqi4869
@diarqoroviqi4869 2 жыл бұрын
Great lesson, it would be greater if you add an iterator example of linked list? Thank you :)
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Thank you & thanks for the suggestion 💙
@dameeldiop341
@dameeldiop341 Жыл бұрын
I've been watching this video as guide to iterate over an object (deep nested, tree data) using RecursiveIteratorIterator & RecursiveArrayIterator but couldn't make it work. Any enlightenment on those recursive classes?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
What is the issue that you are having, can you share more details?
@engenglish610
@engenglish610 Жыл бұрын
In which video did you introduce Route code ?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
Search the playlist & you will find it. I think its 2.23, link to the outline repo is in the description
@houbaben1611
@houbaben1611 2 жыл бұрын
Hello Sir, I am having a problem when I use the iterator interface, I am getting the result but before it there is a message telling me that: Deprecated: Return type of app\InvoiceCollection::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Hello, add mixed as return type to your key method.
@houbaben1611
@houbaben1611 2 жыл бұрын
@@ProgramWithGio thank you very much it works
@b4rt1j1
@b4rt1j1 2 жыл бұрын
Hi, may i ask that next method 4:35 must return void, why are you returning next($this->invoices) ? Its throwing errror in my IDE
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Hey, what error are you getting? The next method does not need to return anything, it can be void, though in some cases it might be useful to return something which is what I'm showing. You can have it as void & just remove the return part, make sure to still have the next($this->invoice)
@b4rt1j1
@b4rt1j1 2 жыл бұрын
@@ProgramWithGio Error was incompatible interface, so i got rid of return stmt and it worked.
@thrldr3106
@thrldr3106 2 жыл бұрын
I didn't quite get why variable $key in the InvoiceCollection class got initialized with 0 whereas you haven't explicitly set it to be. Is this some feature of php8 or am I missing something? Because my interpreter doesn't allow for it.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
It is set to 0 in rewind method explicitly 7:40
@davidmutua6971
@davidmutua6971 Жыл бұрын
Yes because rewind gets called at the very beginning
@giotapetrou2801
@giotapetrou2801 Жыл бұрын
I tried the code and I still get the error "Fatal error: Uncaught Error: Cannot access protected property App\Lesson222\Invoice::$id". I'm I missing something?
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You may have copied code wrongly. Error says you are trying to access protected property. Share the full code if you can
@giotapetrou2801
@giotapetrou2801 Жыл бұрын
class Invoice { protected string $id; public function __construct(private float $amount) { $this->id = random_int(10000, 99999); } } class InvoiceCollection implements \IteratorAggregate { /** * @param Invoice[] $invoices */ public function __construct(public array $invoices) { } public function getIterator(): Traversable { return new \ArrayIterator($this->invoices); } } //index.php $invoiceCollection = new InvoiceCollection([new Invoice(15), new Invoice(25), new Invoice(30)]); echo ''; foreach ($invoiceCollection as $invoice) { echo $invoice->id.' - '. $invoice->amount. ''; } echo '';@@ProgramWithGio
@giotapetrou2801
@giotapetrou2801 Жыл бұрын
thank you in advance!
@abdussukkur9080
@abdussukkur9080 3 жыл бұрын
why 56 no video is private?
@ProgramWithGio
@ProgramWithGio 3 жыл бұрын
It was deleted before it was published & new one was uploaded in its place. Forgot to remove it from playlist. Shouldnt be there anymore. Thanks for letting me know
@HasinthaWeragala
@HasinthaWeragala Жыл бұрын
Fast and Furious PHP edition
@ProgramWithGio
@ProgramWithGio Жыл бұрын
You can slow it down on KZbin buddy 👍
@sujithm.p9776
@sujithm.p9776 2 жыл бұрын
I didn't get when we use iterator. What is the use case.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
When you want to make some class iterable, like a custom collection class as an example.
@sujithm.p9776
@sujithm.p9776 2 жыл бұрын
@@ProgramWithGio okay. I understood there will be a collection of objects and we need to iterate over these objects in foreach this is useful. Apart from that what is the advantage? Is there any advantage while reading data from database? Performance wise?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
@@sujithm.p9776 yes if you are working on a large data set you can use iterators/generator to reduce memory consumption and not load everything in memory at once. We cover generators as well in this series.
@sujithm.p9776
@sujithm.p9776 2 жыл бұрын
@@ProgramWithGio well I understood the scenario. But little curious to know whether laravel uses this concept?
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
Yes, lazy collections use generators
@dhirendrasinghnegi7948
@dhirendrasinghnegi7948 Жыл бұрын
how the invoice collection class is calling these methods in this class nowhere in code you are calling them
@b.c.2177
@b.c.2177 Жыл бұрын
This course is rather demonstration of your skeels than a course for learning PHP. You are talking non stop, like a machine, trying to impress the watchers, but people are not machines. So, it is vey hard to learn PHP watching such a course, even it looks nice and reach.
@ProgramWithGio
@ProgramWithGio Жыл бұрын
I'm not trying to demonstrate anything or impress anyone. I've made editing mistakes in the beginning where I cut out empty spaces making it seem like I don't stop. You can easily slow it down on KZbin by clicking the ⚙️ icon. As you can see from the comments, others find it helpful, so if it doesn't work for you feel free to watch something else. Cheers
@memack101
@memack101 2 жыл бұрын
Thank you.
@ProgramWithGio
@ProgramWithGio 2 жыл бұрын
💙
PHP - Encapsulation & Abstraction -  Full PHP 8 Tutorial
15:23
Program With Gio
Рет қаралды 32 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 79 МЛН
Как Я Брата ОБМАНУЛ (смешное видео, прикол, юмор, поржать)
00:59
Натурал Альбертович
Рет қаралды 4,7 МЛН
How Much Tape To Stop A Lamborghini?
00:15
MrBeast
Рет қаралды 228 МЛН
GUKESH??? DING???????????
17:34
GothamChess
Рет қаралды 174 М.
PHP Traits - How They Work & Drawbacks - Full PHP 8 Tutorial
31:41
Program With Gio
Рет қаралды 33 М.
What Are PHP Magic Methods & How They Work - Full PHP 8 Tutorial
16:55
Program With Gio
Рет қаралды 30 М.
PHP Generators Explained - Full PHP 8 Tutorial
25:47
Program With Gio
Рет қаралды 32 М.
INSANE WORLD CHESS CHAMPIONSHIP GAME 1
25:38
GothamChess
Рет қаралды 602 М.
Why no RONALDO?! 🤔⚽️
00:28
Celine Dept
Рет қаралды 79 МЛН