Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Destroy an object from within the object?

Is there a way in PHP to destroy an object from within that same object?

like image 662
Spot Avatar asked Sep 12 '09 08:09

Spot


People also ask

How do you destruct an object in PHP?

An object is an instance of a class. Using the PHP unset() function, we can delete an object. So with the PHP unset() function, putting the object that we want to delete as the parameter to this function, we can delete this object.

What is used to destroy the value of object in PHP?

unset() destroys the specified variables.

How does PHP remove unused objects?

PHP has a garbage collector which will take care of removing objects from memory once they are not being used any longer.

How do you empty an object in PHP?

To start with stdClass object is empty or null. The default PHP object is stdClass , and the stdClass is commonly an empty class. There are no properties, functions, or parents for stdClass.


1 Answers

If a method is called in the object's context then there has to be at least one reference to that object. And since php only removes unreachable objects the answer is: no.

like image 130
VolkerK Avatar answered Sep 27 '22 19:09

VolkerK