Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php: __destruct questions (OOP newbie)

Tags:

function

oop

php


I'm new at OOP programming. So I have 2 Questions about the __destruct function.

  1. Can I call another object-function from __destruct or are the other functions already undeclarated? For example:

    function __destruct()
        $this->save();
    
  2. Can I also call the __destruct function in my normal code? For example:

    $object_name->__destruct();
    
like image 528
Thomas131 Avatar asked Mar 16 '26 16:03

Thomas131


1 Answers

  1. Yes, that would work I guess, although invoking a save() call inside a garbage collector would be kind of counterintuitive (and terrible design.)

  2. Yes, if you want, or it will be invoked automagically by PHP when no more references to the object exist.

like image 122
OpenSorceress Avatar answered Mar 18 '26 07:03

OpenSorceress