php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: devosc at gmail dot com
New email:
PHP Version: OS:

 

 [2018-12-21 14:32 UTC] devosc at gmail dot com
Description:
------------
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: https://3v4l.org/QlbQm
Works: class not in parent namespace: https://3v4l.org/F3UdP

Doesn't Work: class in same parent namespace: https://3v4l.org/7I3kW


Test script:
---------------
<?php

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-21 14:39 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2018-12-21 14:39 UTC] nikic@php.net
Duplicate of bug #77291, which will be fixed in the next PHP 7.3 release.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 09 21:01:28 2024 UTC