News Feed
Jobs Feed
Sections




News Archive
feed this:

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


DevShed:
Executing Destructors Manually in PHP 5
February 13, 2008 @ 11:27:00

Finishing off their series on destructors in PHP5 applications today, DevShed has posted this new tutorial showing how to manually run the destructors of your class (in case there's ever a need).

In this final tutorial of the series I'm going to show you how to manually trigger a destructor, and in addition you'll learn how to emulate the behavior of this magic method when using PHP 4.

They not only talk about how to call the destructor manually but they also show how to call multiple destructors at the same time to destroy lots of objects at once. And, as promised, they include a method for being able to use a destructor-like bit of functionality in a PHP4 app as well.

0 comments voice your opinion now!
php5 destructor execute manual php4 emulate multiple


DevShed:
Retrieving Information on Several Objects with Destructors in PHP 5
February 07, 2008 @ 10:28:00

DevShed has posted the next-to-last (part four) of their series looking at destructors in PHP5 applications today. This time they focus on passing information back out of the destructors as the script is finishing.

In this fourth article of the series I'm going to teach you how perform this process when working with multiple objects (remember that you already learned how to achieve this using only one class instance).

They start simple, showing how to handle one object to give you a base to work from. They modify this to expand it out and show the management instead of three different user data objects.

0 comments voice your opinion now!
php5 tutorial destructor manage multiple object data


DevShed:
Keeping Track of Objects when Using Destructors in PHP 5
January 30, 2008 @ 11:19:00

Devshed continues their series looking at the use of destructors in PHP5 applications with part three, a method for keeping track of objects you've created during execution.

In this third part of the series, I'm going to show you how to retrieve some useful information about a specific object, including its properties and methods, prior to its being destroyed by the PHP parser via the implementation of a simple destructor.

Their new user class extracts the details about each of the objects right before they're destroyed via a call to get_object_vars and a loop to display the property and its value.

0 comments voice your opinion now!
php5 destructor object track property


DevShed:
Implementing Destructors with Multiple Objects in PHP 5
January 23, 2008 @ 14:57:00

DevShed has posted part two in their series looking at the use of destructors in PHP5. This time they focus on their use with multiple objects inside of an application.

Destructors can be used in all sorts of clever ways in the context of a given PHP 5 application, mostly in those cases where it's necessary to keep track of the status of certain objects prior to their being destroyed by the PHP interpreter. In this second chapter you'll learn how to work simultaneously with multiple classes that concretely implement their respective destructors.

They revisit their previous example with a simple class that's then extended to allow the flexibility to call the same destructor on multiple instances.

0 comments voice your opinion now!
destructor class user data multiple tutorial


DevShed:
Understanding Destructors in PHP 5
January 17, 2008 @ 09:31:00

DevShed has started up yet another PHP-related series today with this new tutorial covering part of PHP5's object functionality - destructors.

This article, the first part of a five-part series, introduces you to destructors and their use with PHP 5 programs. [...] The word "destructor" relates to certain methods or functions of a determined programming language that are responsible for destroying data that, in the context of that particular language, shouldn't exist any longer.

They create a sample class (for storing user information) and show how to integrate a destructor to remove all traces of the user's information from the properties of the class.

0 comments voice your opinion now!
destructor php5 class tutorial example user information destructor php5 class tutorial example user information


Alex Netkachov's Blog:
Optimize PHP memory usage eliminate circular references
September 18, 2007 @ 17:17:21

On his blog today, Alex Netkachov has posted a suggestion of how to combat a common issue facing PHP scripts - their memory usage.

PHP has a build-in garbage collector so you do not need to track the links on the objects, allocate memory for objects and delete them when they are not longer necessary. Things seem so perfect that developers do not even know that their scripts allocate a lot of memory until their server stops processing requests because of the out of memory error.

His example is the processing of a parent/child relationship tree. If not managed correctly, the variables being used could get out of hand quite quickly. Alex recommends the use of a "destructor" at the end of each iteration to help destroy variables and values no longer needed.

0 comments voice your opinion now!
optimize memory circular reference destructor variable optimize memory circular reference destructor variable



Community Events











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


package database unittest podcast security language hhvm facebook release application example component project install symfony2 performance composer framework introduction hack

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