News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Stoimen Popov's Blog:
PHP Don't Call the Destructor Explicitly
November 16, 2011 @ 11:56:43

In this new post to his blog Stoimen Popov talks about calling the "destructor" method of an object and why doing it directly could lead to some issues - like not actually destroying the object before the script ends.

At the end of the script the interpreter frees the memory. Actually every object has a built-in destructor, just like it has built-in constructor. So even we don't define it explicitly, the object has its destructor. Usually this destructor is executed at the end of the script, or whenever the object isn't needed anymore. This can happen, for instance, at the end of a function body. Now if we call the destructor explicitly, which as I said I've seen many times, here's what happen. As you can see calling the destructor explicitly doesn't destroy the object. So the question is...how to destroy an object before the script stops?

He points out that one way to "destroy" an object is to null it out and remove the structure from memory. This is tricky, though, because a clone of the object will still exist in memory, just not the original.

0 comments voice your opinion now!
destructor call directly null clone object


blog comments powered by Disqus

Similar Posts

Jani Hartikainen's Blog: Validating Zend_Forms using model objects

Richard Davey's Blog: Interesting memory use with GD images

Nefarious Designs: Object-Oriented PHP Part 1: Definition

Zend Developer Zone: ZendCon 2010 Podcast - A New Approach to Object Persistence in PHP

Cocoliso's Blog: Adding A Syntax Highlighter To Your Site: The Power Of Geshi


Community Events





Don't see your event here?
Let us know!


language conference code bugfix symfony community introduction tips laravel release interview deployment zendserver framework series api threedevsandamaybe list voicesoftheelephpant podcast

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework