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
Comment Utility
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
Comment Utility
Some required reading here (depending on whether you are PHP4 or PHP5)


PHP5 (hopefully)

Best regards, ~Ray

Expert Comment

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


Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mail Not Sent 6 41
PHP Startup Error 12 27
MySQL database data submission 7 38
how can I dected if URL has variable? 7 21
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
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.

772 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

13 Experts available now in Live!

Get 1:1 Help Now