php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52400 Object 'named' constructor not called in namespaces only
Submitted: 2010-07-22 09:58 UTC Modified: 2011-02-10 17:12 UTC
From: mat999 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.3RC3 OS: linux, debian
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: mat999 at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-22 09:58 UTC] mat999 at gmail dot com
Description:
------------
Very big bad bug, suprised it escaped test until now. Only tested on php-fpm, not cli.

Test script:
---------------
namespace NS1 {
class Test {
    function Test($t){
        die('called');
    }
}
}
namespace {
    new \NS1\Test($t);
    die(':(');
}

Expected result:
----------------
called

Actual result:
--------------
:(

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-22 10:01 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-07-22 10:01 UTC] pajoye@php.net
By design, bug fix.

Methods with the same name as the last element of a namespaced class name will not be treated as constructor anymore. This change doesn't affect non-namespaced classes.

Use the recommended __construct instead.
 [2010-07-22 10:09 UTC] mat999 at gmail dot com
Thanks for the quick reply, can I recomend adding this to the UPGRADING document?
 [2010-07-22 10:17 UTC] pajoye@php.net
-Status: Bogus +Status: To be documented -Package: *General Issues +Package: Scripting Engine problem
 [2010-07-22 10:17 UTC] pajoye@php.net
@doc 

Can you check if it is in there already as well as in the manual?
 [2011-02-10 17:12 UTC] vrana@php.net
-Status: To be documented +Status: Bogus
 [2011-02-10 17:12 UTC] vrana@php.net
Already documented at http://php.net/language.oop5.decon

As of PHP 5.3.3, methods with the same name as the last element of a namespaced class name will no longer be treated as constructor. This change doesn't affect non-namespaced classes.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 09:01:31 2025 UTC