Solved

PHP constructor execution order

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

        parent::__construct();

        // some instructions ...

    }

}

Open in new window

0
 
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)

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
Comment Utility
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

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