7: Delete Objects In OOP PHP | Object Oriented PHP Tutorial For Beginners | PHP Tutorial | mmtuts

Поділитися
Вставка
  • Опубліковано 18 вер 2024
  • Delete Objects In Object Oriented PHP Programming | OOP PHP Tutorial | Learn OOP PHP. In this PHP lesson you will learn to delete objects previously instantiated from our class.
    Link to this playlist: • 1: Introduction To OOP...
    ➤ GET ACCESS TO MY LESSON MATERIAL HERE!
    First of all, thank you for all the support you have given me!
    I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!
    I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.
    I hope you will find it helpful :)
    Material for this lesson: / lesson-material-42361704

КОМЕНТАРІ • 50

  • @ayinlaoluwafemi1993
    @ayinlaoluwafemi1993 6 років тому +6

    You are a good teacher. All your tutorials are very easy to understand, thank you.

  • @meelanuptech1151
    @meelanuptech1151 6 років тому +2

    The OOP tutorial series is too good. But I was expecting you will cover MVC more. I hope you'll create another series for this.

  • @barfgameplay
    @barfgameplay 7 років тому +4

    Great tutorials, really helpful. I hope in one of the next tutorials, after you've covered most of the basic theory, you can make a usable example, like a simple login script.

    • @Dani_Krossing
      @Dani_Krossing  7 років тому +6

      BARF Gameplay I have exercises recorded for episode 11 and 12 ;)

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

    I noticed that if I comment out the __destruct method, yet still call unset on index, the $object is still unset. So what's the point of using the __destruct method at all?

  • @obada6
    @obada6 6 років тому +10

    Thanks you very much dear @mmtuts, but i'm still wondering why i need to delete/destroy my object after work? Do you have a real example for it?

    • @baref0ot455
      @baref0ot455 4 роки тому +2

      One good reason, for example, is that you can give functionality to auto-save upon the exit of an application. You can place that functionality inside the destructor. When the object is to be destroyed (application closes or something), the code that autosaves the data will run as the destructor is executing.

    • @nvmffs
      @nvmffs 4 роки тому +2

      @@baref0ot455 Sure, but why do we need to do it explicitly? Doesn't it run anyway at the end of the script/exit?

    • @baref0ot455
      @baref0ot455 4 роки тому +1

      nvmffs If you do not need custom functionality to execute when the application closes or is exited by a user, then you don’t need to explicitly write a destructor method because it does execute behind the scenes automatically. It is the same as a constructor. It will execute automatically, but if you want to override the default functionality you can but you need to do so explicitly.

  • @f0ru0l0rd
    @f0ru0l0rd 4 роки тому +4

    I'm a little concerned with this one. You say that the destructor is ran after the class is done loading.
    Can you define loading?
    I'm seeing the destructor in the first minute showing AFTER you ran some methods of the object. Is there some limit to the number of methods that must be ran? Must you run all the methods you intend to run and after running those, and seeing no more it "loads"?
    Why in this example is the destructor AFTER the method if it is ran after the class is loaded? Wouldn't that be when it's created?
    Thanks.

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

      Did you get an answer yet?
      Thanks in advance!

  • @PhanTimo01
    @PhanTimo01 7 років тому

    Dude thank you so much. Your tutorials are actually easy to follow. More so than most I have used in the past.

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

    you don't really have to use destruct functions a lot, do you? anyhow good stuff

  • @grosucosminionut8073
    @grosucosminionut8073 5 років тому +2

    wait so let me see if I got this right:
    unset() usually destroys a variable.
    In OOP, using unset() on an object, you say, that what unset() actually does is to explicitly call the destructor which leads to the object being deleted. Ok, so what happens if I don't use a destructor in my class and still use unset() on the object?
    I think that unset() will delete the object, which is to say anything we tell the object to do from the point we used unset on the object onward, will return errors, BUT the destructor will still run it's code, as usual in response to the object being deleted.
    Correct me if I'm wrong.

    • @dustinsandage9387
      @dustinsandage9387 5 років тому

      I second this question.

    • @dustinsandage9387
      @dustinsandage9387 5 років тому +1

      Note, Mike Wilson links to a good explanation of this.

    • @slapmyfunkybass
      @slapmyfunkybass 5 років тому

      Good point, and if the destructor does it anyway what’s the point of running unset? Won’t it just do it twice?

    • @grosucosminionut8073
      @grosucosminionut8073 5 років тому +6

      @@slapmyfunkybass not quite. Let's say we have $obj = new class1;
      Then we call 4 functions form inside the class:
      $obj->function1();
      $obj->function2();
      $obj->function3();
      $obj->function4();
      Then we run this script. The script is executed, the 4 functions do what they are supposed to do and AFTER THAT the __destruct() kicks in and does its stuff.
      Now, say we have the same $obj = new class1;
      And we call the same 4 functions but somewhere in the middle we also use unset();
      $obj->function1();
      $obj->function2();
      unset($obj);
      $obj->function3();
      $obj->function4();
      From the point where we used unset() onward, the object $obj no longer exists. This means that ONLY function1() and function2(); will be executed, the __destruct(); kicks in and does its thing, the object $obj is destroyed and since this happens, function3(); and function4(); will return errors upon execution because the object no longer exists.
      It is not __destruct(); who destroys an object. __destruct(); is a Magic Function, which is a function which gets "triggered" when a particular event takes place. In the case of __destruct(); that event is the deletion of the object. So, in simpler words, __destruct(); doesn't destroy the object, but it is triggered in response to the object being destroyed.

    • @slapmyfunkybass
      @slapmyfunkybass 5 років тому

      Grosu Cosmin Ionut Thanks buddy.

  • @AxxionMarketPlace-iu6ri
    @AxxionMarketPlace-iu6ri Рік тому

    Thank you

  • @aaronargottelopez3488
    @aaronargottelopez3488 3 роки тому

    Thanks

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

    thank you😊

  • @JalalNatsheh
    @JalalNatsheh 4 роки тому

    thank you sooo much man

  • @PabloGnesutta
    @PabloGnesutta 4 роки тому

    Great vid! :)

  • @hieuphamminh8857
    @hieuphamminh8857 4 роки тому

    good tutorial

  • @marshal7969
    @marshal7969 6 років тому +12

    But why ?

  • @slapmyfunkybass
    @slapmyfunkybass 5 років тому

    I’m missing something here - if the destructor does it anyway what’s the point of running unset? Won’t it just do it twice? Putting that to one side, what’s the point of it, I see it on a par with running unset on all your variables at the end of your code?

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

    While the tutorials are good and helpful, for people like me who follow your PHP OOP playlist, the problem is you don't continue where you left off. For example, in the last video we stopped at the Person class then all of a sudden there's new code in the index.php and also new code in the newClass.php file which we didn't write in the previous episodes. I had to pause the video, understand what the new code you wrote is, and copy it.

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

      Last video is newer than this video, because he made "remakes" of some older videos. He mentioned this in the 1st video, and this is why, code here is different than in previous videos. You can recognize them by that, in older videos he's using Sublime text editor and in newer videos, he's using Atom.

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

    Return 'Thank you';

  • @gortex8383
    @gortex8383 5 років тому

    it's not really relevant, but what's the name of the theme ur using, because I like the color scheme. I think it's the default theme of sublime text, but I'm using brackets, and maybe someone made an extension for brackets with this theme. Thx in advance. Had a really good theme once which looked very similar to this one for brackets, but don't know which one that was : ( It's not really that important, but it's nice to have a theme which looks nice to the eye when u are coding.

  • @karukkuvelraja8179
    @karukkuvelraja8179 5 років тому

    is unset used for delete??

  • @zoynuldotcom
    @zoynuldotcom 3 роки тому +1

    I think you are the brother of Elon mask :)

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

    Pause video at :38. Line 13. In that method, why can't we just write it like return $this->data = $newdata, and then echo out that function on the index page like echo $object->setNewProperty("I am a property")............. Then we wouldn't need the getProperty method...

  • @RIMJANESSOHMALOOG
    @RIMJANESSOHMALOOG 5 років тому

    It's for release memory space?

    • @slapmyfunkybass
      @slapmyfunkybass 5 років тому

      AAAjMMMiRRR How necessary is it though? It’s not like we run unset on all our variables.

    • @RIMJANESSOHMALOOG
      @RIMJANESSOHMALOOG 5 років тому +1

      @@slapmyfunkybass depends, multiple large objects created on the run can lead to memory leak i think.

    • @slapmyfunkybass
      @slapmyfunkybass 5 років тому

      AAAjMMMiRRR Okay thanks.

  • @battleofviews638
    @battleofviews638 4 роки тому

    Short video but big confuse :D

  • @АртемВолков-ю5ь
    @АртемВолков-ю5ь 7 років тому

    ths

  • @firdausgull2514
    @firdausgull2514 7 років тому

    First

  • @dfordemo981
    @dfordemo981 3 роки тому

    your screen is quite big.