?
Solved

PHP constructor execution order

Posted on 2008-10-19
3
Medium Priority
?
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
fcardinaux earned 1000 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 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
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.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 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