Link to home
Start Free TrialLog in
Avatar of dbworker1
dbworker1

asked on

Best way to destroy an object instance in php5

in php 5,  what is the best way to destroy an object instance?
For example:
$myObj = new clsMyClass();
... use the object

unset($myObj) ;     // is this the best way?  Is  $myObj = NULL;  better?

Do destructors defined in the class always run in either method above?

Thanks in advance
Avatar of timeshell
timeshell

Do a search on the word "destroy" on the following link and you may find your answer.

http://ca.php.net/oop
ASKER CERTIFIED SOLUTION
Avatar of BrianGEFF719
BrianGEFF719
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of neorush
unset is the proper way to destroy a variable, its faster than say setting $myArray = array();  Your also freeing up more memory by destroying the variable completely.  :-)  (even if it is only a little)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial