Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 305013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:20:02+00:00 2026-05-12T07:20:02+00:00

Given the class Foo with an old-style constructor class Foo { public function Foo()

  • 0

Given the class Foo with an old-style constructor

class Foo
{
    public function Foo()
    {
        //does constructing stuff
    }
}

Is there any functional difference between calling the parent constructor with a new style constructor or the old style constructor?

class Bar extends Foo
{
    public function Bar()
    {
        //does it matter?
        //parent::__construct();
        //parent::Foo();
    }
}

Put another way, is there anything special about the static call

parent::__construct()

when it’s made from a constructor, or is it just a standard static call?

Before the Best Practices Flying Monkeys descend, I’m dealing with some legacy code and trying to understand the consequences of everything that’s going on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:20:02+00:00Added an answer on May 12, 2026 at 7:20 am

    I would say both syntax do exactly the same thing…

    Edit : after writting the rest of the answer, actually, this is not entirely true ^^ It depends on what you declare ; see the two examples :

    If you define Foo as constructor, and call it with __construct, it seems it’s working ; the following code :

    class Foo {
        public function Foo() {
            var_dump('blah');
        }
    }
    
    class Bar extends Foo {
        public function Bar() {
            parent::__construct();
        }
    }
    
    $a = new Bar();
    

    Outputs

    string 'blah' (length=4)
    

    So, all OK for now 😉

    On the other way, if you define __construct, and call Foo, like this :

    class Foo {
        public function __construct() {
            var_dump('blah');
        }
    }
    
    class Bar extends Foo {
        public function Bar() {
            parent::Foo();
        }
    }
    
    $a = new Bar();
    

    It’ll get you a Fatal Error :

    Fatal error: Call to undefined method Foo::foo()
    

    So, if your class is declared with old-syntax, you can call it both ways ; and if it’s defined with new (PHP5) syntax, you must use that new syntax — which makes sense, afterall 🙂

    BTW, if you want some kind of “real proof”, you can try using the Vulcan Logic Disassembler, that will give you the opcodes corresponding to a PHP script.


    EDIT after the comment

    I’ve uploaded the outputs of using VLD with both syntaxes :
    – vld-construct-new.txt : when declaring __construct, and calling __construct.
    – vld-construct-old.txt : when declaring Foo, and calling __construct.

    Doing a diff between the two files, this is what I get :

    $ diff vld-construct-old.txt vld-construct-new.txt
    25c25
    < Function foo:
    ---
    > Function __construct:
    29c29
    < function name:  Foo
    ---
    > function name:  __construct
    44c44
    < End of function foo.
    ---
    > End of function __construct.
    71c71
    < Function foo:
    ---
    > Function __construct:
    75c75
    < function name:  Foo
    ---
    > function name:  __construct
    90c90
    < End of function foo.
    ---
    > End of function __construct.
    

    (Unified diff is much longer, so I’ll stick to using the default format of “diff” here)

    So, the only differences in the disassembled opcodes are the names of the functions ; both in the Foo class and in the Bar class (that inherits the __construct / Foo method of class Foo).

    What I would really say is :

    • If you are writting PHP 5 code (and, in 2009, I sincerely hope you do ^^ ), then, just use the __construct syntax
    • You you have to maintain some old PHP 4 code you can’t migrate to PHP 5 (you should), then, use the Foo syntax…

    As the sidenote, the documentation says (quoting) :

    For backwards compatibility, if PHP 5
    cannot find a __construct() function
    for a given class, it will search for
    the old-style constructor function, by
    the name of the class.

    Effectively, it means that the only
    case that would have compatibility
    issues is if the class had a method
    named __construct() which was used
    for different semantics.

    So, I really think there is not that much of a difference 🙂

    Did you encounter some kind of strange problem, that you think is caused by something like a difference between the two syntaxes ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 221k
  • Answers 221k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I got it working. I just added dragController.setBehaviorDragStartSensitivity(1); to my… May 13, 2026 at 12:12 am
  • Editorial Team
    Editorial Team added an answer SVN branches can be used for this, but you keep… May 13, 2026 at 12:12 am
  • Editorial Team
    Editorial Team added an answer Personally for me it"depends". Usually I would prefix everything with… May 13, 2026 at 12:12 am

Related Questions

Suppose you're maintaining an API that was originally released years ago (before java gained
I'm working on old code that relies heavily on the exception specifications behavior described
Given the following in PHP: <?php class foo { public $bar; function __construct() {
I usually, almost without thinking anymore, use forward declarations so that I won't have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.