Solved

PHP constructor execution order

Posted on 2008-10-19
3
266 Views
Last Modified: 2013-12-13
In C++, when there is an inheritance hierarchy, constructors are executed in a special order (eg, Base Class, than Derived). Does PHP have anything like this?
0
Comment
Question by:msosno
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
fcardinaux earned 250 total points
ID: 22755087
You need to call the parent constructor in the derived class constructor, like in the following code.

This determines the order in which constructors are called.
class myDerived extends myParent 
{
    function __construct()
    {
        // some instructions ...
        parent::__construct();
        // some instructions ...
    }
}

Open in new window

0
 
LVL 109

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 22761281
Some required reading here (depending on whether you are PHP4 or PHP5)

PHP4
http://us3.php.net/manual/en/language.oop.php

PHP5 (hopefully)
http://us3.php.net/manual/en/language.oop5.php

Best regards, ~Ray
0
 
LVL 8

Expert Comment

by:fcardinaux
ID: 22764750
You're right, Ray. I forgot to mention that my example was in PHP5: http://us3.php.net/manual/en/language.oop5.decon.php

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

774 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question