PHP
  Home arrow PHP arrow Understanding Destructors in PHP 5
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
eWeek
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Understanding Destructors in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2008-01-16

    Table of Contents:
  • Understanding Destructors in PHP 5
  • Building a Sample
  • Introducing Class Destructors
  • Testing the Previous User

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Understanding Destructors in PHP 5
    (Page 1 of 4 )

    Despite the scary-sounding name, destructors aren't evil. Indeed, their use is often necessary to help keep your applications running properly. This article, the first part of a five-part series, introduces you to destructors and their use with PHP 5 programs.

    Generally, people tend to associate the term “destructor” with something that will be used with bad intentions. And to be frank, this attitude has some common sense behind it. After all, if there is such a thing with that scary name, well, it must be evil, and capable of destroying other stuff also.

    Fortunately, in the terrain of software development, things aren’t really so drastic really (excepting when your boss isn’t in the mood for jokes). 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.

    Speaking more specifically, PHP has a certain number of native routines that are clear examples of “destructive” behaviors that can be healthy during the execution of a specific application. To cite a paradigmatic example, consider its garbage recollection mechanism. It is charged with removing expired session data, useless database links, and so forth. Undoubtedly, under determined conditions, functions or methods that destroy certain data are not only useful, but completely mandatory.

    However, aside from the intrinsic destruction mechanisms provided by PHP, there’s another one that was introduced within the improved object model of PHP 5, which actually will be subject of this article series. Obviously, if you read this tutorial’s title, then you’ll possibly know what I’m talking about: the so-called destructor methods.

    In case you didn’t know, PHP 5 provides programmers with the capacity for defining inside a given class, a special method called “__destruct()”, which as its name suggests, will be automatically invoked when an object instantiated from that class no longer exists in the context of a certain application.

    In the same way that a constructor is executed automatically when a new object is created in PHP, their “__destruct()” counterpart will be called up when the object in question is removed from the web server’s memory. Continuing with the similarities between constructors and destructors, destructors also have a non-default implementation, which gives programmers the ability to define them according to their specific needs.

    Now that I provided you with a brief introduction to what destructors are in PHP 5, in this series of articles I’m going to show you the basics of how to work with them. The corresponding theory will be complemented with illustrative hands-on examples that you’ll be able to test and study easily, so you can start using them with your own PHP 5-driven applications.

    At this point, it’s time to get rid of the preliminaries and begin learning how to use destructors with PHP 5, so let’s move on and start this instructive journey right now!

    More PHP Articles
    More By Alejandro Gervasio


       · The improved object model of PHP 5 permits to declare destructors. Basically, a...
     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway