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

 
Developer Updates  
Free Website Content 
 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: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT