I have a pointer to an object, which I want to release, and then create a new one.
What I tried:
$this->myObject = null;
$this->myObject = new myObject($newVar);
Should this work? Am I doing it wrong?
I tried calling __destructor() manually but that triggered an “unknown function” error.
PHP does not have pointers.
But, yes, this is fine. You don’t need to set to
nulleither; the original, now-dangling object will be garbage collected just like any other object.Example: