|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77333 Trait constructor not working (same parent namespace)
Submitted: 2018-12-21 14:32 UTC Modified: 2018-12-21 14:39 UTC
From: devosc at gmail dot com Assigned:
Status: Duplicate Package: Class/Object related
PHP Version: 7.3.0 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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: devosc at gmail dot com
New email:
PHP Version: OS:


 [2018-12-21 14:32 UTC] devosc at gmail dot com
The constructor method is not being called when a class is in the same namespace as the trait containing the constructor.

Works: class in global namespace:
Works: class not in parent namespace:

Doesn't Work: class in same parent namespace:

Test script:

namespace Test {
    trait Base {
        public $config = [];
        function __construct($config = [])
            $this->config = $config;

    class Config {
        use Base;

namespace {

    $test = new Test\Config(['foo' => 'bar']);

    echo isset($test->config['foo']) ? 'Success: foo is set' : 'Error: foo is not set';

Expected result:
Success: foo is set

Actual result:
Error: foo is not set


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-21 14:39 UTC]
-Status: Open +Status: Duplicate
 [2018-12-21 14:39 UTC]
Duplicate of bug #77291, which will be fixed in the next PHP 7.3 release.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Aug 14 09:05:44 2022 UTC