Results 1 to 6 of 6

Thread: What are parent::construct() and parent::destruct() in PHP?

  1. #1
    Join Date
    Aug 2006
    Posts
    114

    What are parent::construct() and parent::destruct() in PHP?

    Hi friends,
    I have completed some basic programs that are initials for the PHP programming language. I want to know about the parent::construct() and parent::destruct() which are used in coding of PHP. I was checking my tutorial and found this and I don't know anything about it. So thought that you guys would be useful. So please tell me what are parent::construct() and parent::destruct() in PHP? reply me soon.!!
    |===================|
    |YAY if that made sense...|
    |===================|

  2. #2
    Join Date
    Mar 2008
    Posts
    349

    Re: What are parent::construct() and parent::destruct() in PHP?

    PHP 5 allows developers to declare constructor methods for classes. The classes have a constructor method call this method whenever you create a new instance of the object, which is suitable for any initialization that the object may need before being used. Parent constructors are not called implicitly if the child class defines a constructor. If you want to use a parent's constructor, it will be necessary to call parent::construct (). Hope that you got the basic things from this post.!!

  3. #3
    Join Date
    Mar 2008
    Posts
    672

    Re: What are parent::construct() and parent::destruct() in PHP?

    The following is an example of using new unified constructors :
    PHP Code:
    <?php
    class BaseClassDemo {
       function 
    construct() {
           print 
    "In BaseClass constructor\n";
       }
    }
     
    class 
    SubClass extends BaseClassDemo {
       function 
    construct() {
           
    parent::construct();
           print 
    "In SubClass constructor\n";
       }
    }
     
    $obj = new BaseClassDemo();
    $obj = new SubClass();
    ?>

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: What are parent::construct() and parent::destruct() in PHP?

    PHP 5 introduces a destructor concept similar to other object oriented languages such as C + +. The destructor method will be called as soon as all references to a particular object are removed or when the object is explicitly destroyed or in any order of the shutdown. Like constructors, parent destructors will not be called implicitly by the engine. To run a parent destructor, you need to explicitly call parent::destruct in the destructor body.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: What are parent::construct() and parent::destruct() in PHP?

    The destructor will be called even if the script is stopped using the function exit (). Call the function exit () in a destructor will not carry out other routine arrest. Destructors called during the script shutdown have already sent the HTTP headers. The working folder in the phase of the shutdown script may be different with other APIs Attempting to throw an exception from a destructor (called at the end of the script) makes a fatal mistake. An exception normally 'bubbles up' to higher and higher contexts until it is caught, but because a destructor or shutdown function is called not within execution flow but in response to a special PHP event.

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: What are parent::construct() and parent::destruct() in PHP?

    In order to run a parent destructor, one would have to explicitly call parent::destruct() in the destructor body. The destructor will be called even if script execution is stopped using exit(). Calling exit() in a destructor will prevent the remaining shutdown routines from executing. Unlike with other methods, PHP will not generate an E_STRICT level error message when construct() is overridden with different parameters than the parent construct() method.

Similar Threads

  1. boot from VHD without parent OS
    By Symbiot in forum Operating Systems
    Replies: 2
    Last Post: 12-05-2011, 05:29 PM
  2. How to update a parent zone
    By Santiaago in forum Technology & Internet
    Replies: 5
    Last Post: 04-03-2010, 12:44 PM
  3. How to add an Image to a parent node in a treeview?
    By Casie in forum Software Development
    Replies: 4
    Last Post: 27-01-2010, 05:02 PM
  4. VB.NET Parent Form Reference
    By ASTON in forum Software Development
    Replies: 3
    Last Post: 24-06-2009, 12:41 PM
  5. CSS : How to float outside parent div
    By Valerian in forum Software Development
    Replies: 4
    Last Post: 21-05-2009, 12:03 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,053,068.58023 seconds with 17 queries