php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46022 constructor version compatable
Submitted: 2008-09-08 13:54 UTC Modified: 2008-09-08 18:56 UTC
From: vivekanandan at classof1 dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0alpha2 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: vivekanandan at classof1 dot com
New email:
PHP Version: OS:

 

 [2008-09-08 13:54 UTC] vivekanandan at classof1 dot com
Description:
------------
when we define both constructor types as class name as construct name and __construct keyword , we need to produce error 

Reproduce code:
---------------
class UserInfo{
function __construct(){
	print "<br>  __construct function is called ";
}


function UserInfo(){
print "UserInfo constructor is called";
}

function getUserInfo(){
	print "<br>This is User Defined function ";
}
}

$obj = new UserInfo();
$obj->getUserInfo();

Expected result:
----------------
produce error : Constructor cannot be difined more than once

Actual result:
--------------
 __construct function is called 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-09-08 18:56 UTC] jani@php.net
RTFM: "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."

So in this case as you provide the "new" style (and proper) 
constructor the BC fallback is simply ignored. No bug here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 03 20:00:01 2025 UTC