PHP constructor execution order

Posted on 2008-10-19
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?
Question by:msosno
  • 2

Accepted Solution

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 ...


        // some instructions ...



Open in new window

LVL 108

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)


PHP5 (hopefully)

Best regards, ~Ray

Expert Comment

ID: 22764750
You're right, Ray. I forgot to mention that my example was in PHP5:


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php date - compare 4 40
Animated .jpg? 13 61
Form Processing in PHP 11 32
How do I make my dropdowns depended within a JQuery Modal Dialog box. 3 12
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses how to create an extensible mechanism for linked drop downs.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now