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

preview_player
Показать описание
In this lesson, you will learn what iterators are & how to work with them in PHP. It may sound scary but it's actually pretty simple. With iterators you can define how you want your objects to be iterated on, by default when you iterate over objects in PHP it will iterate on visible properties on the object but sometimes you may want to iterate on a specific property of the object instead. Learn what Iterator, IteratorAggregate & Traversable interfaces are, what iterable data type is & how to implement a basic collection pattern that you might be familiar with from frameworks like Laravel.

SOME OF THE WAYS YOU CAN SUPPORT THE CHANNEL
👍 Smash the like button
🤝 Subscribe to the channel & turn the notifications on
💬 Post comments, any feedback is greatly appreciated
THANK YOU!

LESSON 2.22

RESOURCES

CHAPTERS
00:00 - Iterating over objects
01:33 - Traversable, Iterator & IteratorAggregate interfaces
02:11 - Implement simple collection class using Iterator interface
07:50 - SPL iterators & refactoring collection to use IteratorAggregate interface
10:26 - Iterable type & type-hinting
Рекомендации по теме
Комментарии
Автор

i have been using youtube for 15 years to study, hands down your the best teacher, tha a man can hope for

ousssika
Автор

Hands down, this is the best explanation of Iterators I've even seen. Thanks!

Vitalii-mr
Автор

Jaw drop, I had no friggin clue something like this was possible. This is the best PHP course I've ever seen.

lynic-
Автор

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

Nooneandeveryone
Автор

Thank you mush for one another topic. Very interesting to study PHP with your lessons.🙂

ВладиславСоколенко-уй
Автор

I'm really enjoying this series and learning more
Respect from Pakistan.

nextLevelYou-do
Автор

This the best class about iterators with examples. Keep it up will done.

khusamalfas
Автор

Thank you so much for sharing this content of excellent quality.

FranciscoJunior
Автор

Great lesson, I've bagged another one (need to practice though). Thanks alot Gio.

Zubbee
Автор

i love you bro thank you so much for all those videos clear and simple example that make it easy.

Haamome
Автор

Thank you for tor sharing this, great video!

neriusshaqiri
Автор

Great lesson, it would be greater if you add an iterator example of linked list? Thank you :)

diarqoroviqi
Автор

instead of implementing iterator, why not just use nested foreach loop?
or you just did it to show the implementation of iterator?

abdallahdamra
Автор

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?

derzskyi
Автор

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

brtj
Автор

9:50 off topic: i would have used a trait for getIterator, leaving more freedom to inherit from another class..

paulfontaine
Автор

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

houbaben
Автор

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?

dameeldiop
Автор

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.

thrldr
Автор

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?

giotapetrou
join shbcf.ru