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

  • SEARCH
  • Home
  • 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 9257341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:09:09+00:00 2026-06-18T12:09:09+00:00

Currently, PHP supports two naming conventions for constructors. PHP 4 supported Java-style constructors: class

  • 0

Currently, PHP supports two naming conventions for constructors. PHP 4 supported Java-style constructors:

class A
{
    public function A()
    {
        echo "I'm a constructor for class A!";
    }
}

PHP 5 supports both the Java-style constructors and a “magic method” syntax:

class A
{
    public function __construct()
    {
        echo "I'm a constructor for class A!";
    }
}

The Java-style syntax is slated for deprecation, and some features of it don’t work in the latest PHP. However, it has an interesting property that I know of no analogue for with the “magic method” syntax. If derived class foobar has no explicit constructor, then the foobar method of the base class becomes the foobar constructor:

class A
{
    public function A()
    {
        echo "I'm a constructor for class A!";
    }

    public function B()
    {
        echo "I'm a constructor for class B!";
    }
}

class B extends A
{
}

Since Java-style constructors are being deprecated, what will become of the set-the-constructor-in-the-parent language feature?

  • 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-06-18T12:09:10+00:00Added an answer on June 18, 2026 at 12:09 pm

    You probably learned this here, for PHP 4.

    As you already know, in PHP 5 documentation (here) it is stated that if no __construct() is used or inherited, the old syntax kicks in as a fallback:

    For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, and the class did not inherit one from a parent 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 the old syntax should still be valid, as PHP 5.4.11. There is no explicit plan for deprecation, right now, even if it’s foreseeable.

    Anyway, when (and if) they will be dropped, this feature will be dropped too as there is no way to reproduce it with the __construct() syntax.

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

Sidebar

Related Questions

I am building a web application that is currently PHP with MySQL. There is
I'm currently using PHP, JAVASCRIPT, MYSQL, XHTML, CSS to develop my site. Note that
I am currently using PHP/MySQL and the jQuery timeago plugin. Basically, I need to
I am building an application currently in PHP and I am trying to decide
Currently in my PHP-based applications I use a file, for instance services.php and call
Currently developing a PHP framework and have ran into my first problem. I need
I currently have a PHP form that uses AJAX to connect to MySQL and
I'm currently writing a PHP application and drivers (classes) for the database engines. I
I am currently running a PHP script that queries the database and then sends
I'm currently in need of a (preferably open-source) free push server, that supports both

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.