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 6750759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:50:47+00:00 2026-05-26T12:50:47+00:00

Why can’t I use code like this? <?php class NoConstructor { } class ChildWithConstructor

  • 0

Why can’t I use code like this?

<?php

class NoConstructor {
}

class ChildWithConstructor extends NoConstructor {
    public function __construct() {
        parent::__construct();
        // do something
    }
}

$foo = new ChildWithConstructor();
// **Fatal error: Cannot call constructor in file.php on line 8**

Eg. Java classes have default, no args constructor. It can be called even if it’s not explicitly defined.

PHP behavior can cause troubles when we remove no args constructor from parent class, eg. when we think it’s not needed any more.

Does anyone know why PHP creators made it this way?

  • 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-26T12:50:48+00:00Added an answer on May 26, 2026 at 12:50 pm

    Java classes have default, no args constructor.

    Does anyone know why PHP creators made it this way?

    Java was a planned language. It was rigorously considered and formally specified from the get-go. It was intended to last as long as possible with minimal changes for sake of backwards and forwards compatibility, for simplicity to developers and implementers alike. The definitely didn’t succeed to the degree they hoped, but you can still take Java 1.0 code, compile it and run it on modern VMs.

    PHP’s designers never planned the language to nearly such an extreme. They make it up as they go along. For better or worse, they’re moderately willing to throw the language apart and rebuild it in the next version. It’s changed unrecognizably since PHP 1 and 2. Even recently, in PHP 5, you had the dramatic change from by-value to by-reference semantics for objects. It’s that same brilliant methodology that brought us magic quotes, the lack of Unicode, inconsistently named (and frequently renamed) functions, and a parser that without even a hint of error (even with error_reporting(-1);), will merrily interpret the numeric literal 09 as 0.

    PHP behavior can cause troubles when we remove no args constructor from parent class, eg. when we think it’s not needed any more.

    You could request this be changed on bugs.php.net, but chances are they’ll ignore it or fob you off with "Sorry, but your issue does not imply a problem in PHP itself…".

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

Sidebar

Related Questions

Can I use the following across all browsers? <a href=# onclick=doSomething()>Click here.</a> Is this
Can anyone tell me how I can display a status message like 12 seconds
Can I get a 'when to use' for these and others? <% %> <%#
Can anyone help me see where I am missing this? I am trying to
Can anyone tell me what's wrong with this robots.txt? http://bizup.cloudapp.net/robots.txt The following is the
Can anyone pls let me know the exact c++ code of case sensitive comparison
Can i get the source code for a WAMP stack installer somewhere? Any help
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Can someone point to me or explain if this is true, you must not

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.