PHP
  Home arrow PHP arrow Using the Clone Magic Function 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

Using the Clone Magic Function in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 3
    2009-06-15


    Table of Contents:
  • Using the Clone Magic Function in PHP 5
  • Review: the sleep and wakeup magic functions
  • Triggering functions in the background when cloning objects
  • Calling the clone method when cloning an object

  • 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


    Using the Clone Magic Function in PHP 5
    ( Page 1 of 4 )

    If you’re an eager PHP developer who wants to have at your disposal a quick guide that shows you how to work with the most relevant magic functions provided by PHP 5, then this series of articles might be what you’re looking for. In this fifth part of a seven-part tutorial on magic functions, we'll briefly review the sleep and wakeup functions, and then tackle the clone function.

    Undoubtedly, the release of PHP 5 quite some time ago brought with it a significant advance in the way that web applications are developed nowadays. This is despite the high level of backward compatibility it maintains with its venerable predecessor, PHP 4.

    Certainly it’s not breaking news that PHP 5 comes packaged with a robust object model and a whole new set of functions and time-saving libraries, not to mention its handy exception mechanism, which allows it to handle errors and exceptional events in a truly efficient and elegant way.

    Of course, when I use the term “functions,” I’m not talking about only the common ones that perform specific tasks such as reading data from a file or applying a filter to a supplied variable. I'm also referring to the magic ones; that is, the functions that have no a concrete implementation by default and are called automatically by the PHP engine in response to certain events.

    The trio comprised of the “__set()”, “__get()” and “__call()” methods offer a classic example of magic functions that are used when developing object-oriented PHP applications, but there are a few others that certainly deserve deeper analysis as well.

    And speaking of magic functions, you’ll surely recall that I left off the last article discussing the use of the “__sleep()” and “__wakeup()” methods, which are invoked by the PHP interpreter when serializing and unserializing a specified object.

    Though these methods were only responsible for echoing to the screen some basic messages when called, the examples developed in the aforementioned tutorial should give you a clear idea of how to use them in a more helpful manner.

    Though, as I said before, there are other magic functions that are worth exploring in detail as well. So, with that goal in mind, in this fifth part of the series I’m going to take a closer look at the “__clone()” method, which as its name suggests, is called behind the scenes when using the “clone” PHP keyword.

    So, now it’s time to leave the theory behind us and start learning now to use this brand new magic function. Let’s get started right away!



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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