PHP - Object Cloning & Clone Magic Method - Full PHP 8 Tutorial
Вставка
- Опубліковано 18 вер 2024
- In this lesson, you will learn how to clone objects & the magic method that gets called after an object has been cloned in PHP.
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
⭐ Become a Patreon: / programwithgio
THANK YOU!
LESSON 2.18
Course Outline - github.com/gge...
Course Playlist - • Learn PHP The Right Wa...
RESOURCES
Lesson 2.16 Comparing Objects - • PHP Variable Storage &...
I wake up at 4:30 AM every day and spend the first 3 hours of my day watching this playlist. Can't wait to see how I'll do with the exercise project!
That's awesome, thank you
Wow sasha, me too at 4.30am. Best time to get things into the head. ❤
@@truthteachers Awesome bro! I believe in you
Love this playlist. Even though I use PHP day in day out, this is a great refresher and provides some of the best explanation / examples I've ever seen. Plus gain some insight on aspects of PHP I don't use, but might find a use for.
Glad it was helpful
I'm glad i found your channel, thank you for your efforts
You're welcome and thank you 🙌
Bro, Initially I had trouble following the course becoz i was moaning there was no source code. But i am going through the Part 2 all over again and this time entering the code, it really made sense and i was understanding things better. Thank you so much bro.
Thank you, happy to hear that 🙌🙌
Great content and very well explained.
Nice work! Clear and objective explanation
Thank you Ryan
thank you for lesson!
You're welcome
I really do like your videos Gio, that's why I really do like and comment. It's the least I can do for such great content.
Thank you 🙌. I appreciate it 💙
Congratz 19k subscriber
Thank you 🙌💙
Thank you
You're welcome
Thank you so much!!!
You're welcome
Clear explanation Thanks for the video
You're welcome 💙
Thank you.
You're welcome
Thanks
Thank you for support 💙
Hello Gio, thank you for the great explanation on the cloning of objects topic. What would be a practical scenario where we would implement/use this oop feature?
There can be many use cases, some that come to mind are a way to copy an object and keep it as a way to revert your object back to what it was before you made changes to it. Or you may want to clone a configuration or a DTO object like an address
@@ProgramWithGio Thank you!
Great job, it's awesome.
Thank you! Cheers!
Hi Gio , what do you mean exactly by shallow copy of an object?
Hello Rosario. Shallow copy means that when object is copied its values are copied normally but if the value is an object itself then it's reference is copied, so if you make a change on the object property on your cloned object it makes change on the original object as well that you copied/cloned from. Deep copy makes the actual real copy even for inner objects.
Just to mention that you can use __FUNCTION__ to print name of the function :)
Sure or __METHOD__ which would apply more in this context since we are dealing with methods but sometimes var_dump is all thats needed :D
@@ProgramWithGio anyway, thanks for this tutorials, you rock 🙃👍
You're welcome, thank you
3:20, Can't we just use self::__construct(), to call the constructor and generate new unique ID? i did it and it works, is it a bad practice or something?
Yea in my opinion it doesnt look right to call constructor inside your clone
Is it correct to say that the 'clone' keyword in PHP is an implementation of the Prototype pattern?
If you are referring to Prototype pattern & not prototype from javascript then yes
Thanks for the video, Gio!
0:51 I wonder why the dumped objects have these out-of-order IDs: #3, #2 and then #4. I ran the same code on my machine and got #1, #2 and #3. How can that be explained?
I've ran the code multiple times during recording, that could be the reason. The numbers should indicate in which order the objects were instantiated if I'm not mistaken regardless of which order you are dumping them out.
Hi Gio. I like your contents. Do you have video tutorials of a real web project? Are you planning doing that and share it on the youtube? Thank you
Hello. Not yet but yes it's planned
thanx
You're welcome 🙌
Thank you SO MUCH!!!
You're welcome!