Bug #77333 [Opn->Dup]: Trait constructor not working (same parent namespace)

From: Date: Fri, 21 Dec 2018 14:39:59 +0000
Subject: Bug #77333 [Opn->Dup]: Trait constructor not working (same parent namespace)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218549@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77333&edit=1

 ID:                 77333
 Updated by:         nikic@php.net
 Reported by:        devosc at gmail dot com
 Summary:            Trait constructor not working (same parent
                     namespace)
-Status:             Open
+Status:             Duplicate
 Type:               Bug
 Package:            Class/Object related
 PHP Version:        7.3.0
 Block user comment: N
 Private report:     N

 New Comment:

Duplicate of bug #77291, which will be fixed in the next PHP 7.3 release.


Previous Comments:
------------------------------------------------------------------------
[2018-12-21 14:32:40] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=77333&edit=1


Thread (2 messages)

« previous php.bugs (#218549) next »