php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #41819 Old style Constructor inconsistencies
Submitted: 2007-06-27 07:46 UTC Modified: 2007-08-16 13:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: oancea at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.2.3 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: oancea at gmail dot com
New email:
PHP Version: OS:

 

 [2007-06-27 07:46 UTC] oancea at gmail dot com
Description:
------------
There is an inconsistency between the old style class constructor (class name) and the new one (__construct) when defining interfaces (see reproduce code bellow).

Reproduce code:
---------------
interface IConfigurator {

  public function __construct();

}

class XmlConfigurator implements IConfigurator {

  public function XmlConfigurator() {
    printf("%s\n", __METHOD__);
  }

}

$config = new XmlConfigurator();


Expected result:
----------------
One of:

 * XmlConfigurator::XmlConfigurator
 * Fatal error: old style constructor is deprecated

Actual result:
--------------
Fatal error: Class XmlConfigurator contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (IConfigurator::__construct) in

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-27 08:28 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2007-06-27 08:48 UTC] oancea at gmail dot com
How about this one:

abstract class IConfigurator {

  public abstract function __construct();

}

class XmlConfigurator extends IConfigurator {

  public function XmlConfigurator() {
    printf("%s\n", __METHOD__);
  }

}

$config = new XmlConfigurator();


Can you point me to the exact documentation where it states that the old style constructor should not be used, at least not in interfaces or in abstract classes?

Thank-you.
 [2007-06-27 08:50 UTC] tony2001@php.net
Nobody said it cannot be used, but __construct() and XMLConfigurator() are two different functions, so the result you get is pretty much expected.
 [2007-06-27 08:59 UTC] oancea at gmail dot com
Well, as far as I can see, both of those functions are constructors, one (__constructor) specifies the signature of an object, and the other one implements it.

According to this bug (fixed in 5.1): http://bugs.php.net/bug.php?id=35720 in the end is the same method.

Anyway, thank you for your time, and I hope that at least the documentation will add my example as "don't do this because __construct and old style constructor are two different functions for interfaces or abstract classes"!
 [2007-06-27 10:11 UTC] oancea at gmail dot com
Re-open to mark as a documentation problem.
 [2007-08-16 13:22 UTC] vrana@php.net
Documentation is not saying that classname() is an alias of __construct(). It says that it is fallback if __construct() is not defined.

Your interface declares method which is not defined in the class.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 20 21:00:02 2025 UTC