Solved

PHP constructor execution order

Posted on 2008-10-19
3
269 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

856 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