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 &...

КОМЕНТАРІ • 52

  • @Sasha-li2bn
    @Sasha-li2bn 2 роки тому +16

    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!

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +3

      That's awesome, thank you

    • @truthteachers
      @truthteachers Рік тому +1

      Wow sasha, me too at 4.30am. Best time to get things into the head. ❤

    • @Sasha-li2bn
      @Sasha-li2bn Рік тому +2

      @@truthteachers Awesome bro! I believe in you

  • @thisbridgehascables
    @thisbridgehascables Місяць тому +1

    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.

  • @aleksandrkanygin2672
    @aleksandrkanygin2672 3 роки тому +4

    I'm glad i found your channel, thank you for your efforts

  • @truthteachers
    @truthteachers Рік тому +2

    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.

  • @federicobau8651
    @federicobau8651 2 роки тому +3

    Great content and very well explained.

  • @ryanw.fonseca4079
    @ryanw.fonseca4079 3 роки тому +1

    Nice work! Clear and objective explanation

  • @ilya_123__
    @ilya_123__ 9 місяців тому

    thank you for lesson!

  • @Zubbee
    @Zubbee 2 роки тому

    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.

  • @phpisdead
    @phpisdead 2 роки тому

    Congratz 19k subscriber

  • @fairouzben4043
    @fairouzben4043 5 місяців тому

    Thank you

  • @MaximeMorlet
    @MaximeMorlet Рік тому

    Thank you so much!!!

  • @user-mo3cw6go7c
    @user-mo3cw6go7c Рік тому

    Clear explanation Thanks for the video

  • @memack101
    @memack101 2 роки тому

    Thank you.

  • @truthteachers
    @truthteachers Рік тому +1

    Thanks

  • @bogdanmarian3786
    @bogdanmarian3786 3 місяці тому

    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?

    • @ProgramWithGio
      @ProgramWithGio  2 місяці тому +1

      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

    • @bogdanmarian3786
      @bogdanmarian3786 2 місяці тому

      @@ProgramWithGio Thank you!

  • @FranciscoJunior29
    @FranciscoJunior29 2 роки тому

    Great job, it's awesome.

  • @rosarioveneruso9928
    @rosarioveneruso9928 2 роки тому +1

    Hi Gio , what do you mean exactly by shallow copy of an object?

    • @ProgramWithGio
      @ProgramWithGio  2 роки тому +2

      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.

  • @bogdansipka6503
    @bogdansipka6503 10 місяців тому

    Just to mention that you can use __FUNCTION__ to print name of the function :)

    • @ProgramWithGio
      @ProgramWithGio  10 місяців тому +1

      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

    • @bogdansipka6503
      @bogdansipka6503 10 місяців тому

      @@ProgramWithGio anyway, thanks for this tutorials, you rock 🙃👍

    • @ProgramWithGio
      @ProgramWithGio  10 місяців тому

      You're welcome, thank you

  • @barteqzz5616
    @barteqzz5616 2 місяці тому

    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?

    • @ProgramWithGio
      @ProgramWithGio  Місяць тому

      Yea in my opinion it doesnt look right to call constructor inside your clone

  • @Vitalii-m6r
    @Vitalii-m6r Рік тому

    Is it correct to say that the 'clone' keyword in PHP is an implementation of the Prototype pattern?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      If you are referring to Prototype pattern & not prototype from javascript then yes

  • @ryanford516
    @ryanford516 Рік тому

    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?

    • @ProgramWithGio
      @ProgramWithGio  Рік тому

      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.

  • @andrepedrosa1525
    @andrepedrosa1525 2 роки тому

    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

  • @bakre_dev8728
    @bakre_dev8728 Рік тому

    thanx

  • @user-bf5sb1fs1w
    @user-bf5sb1fs1w 2 роки тому

    Thank you SO MUCH!!!