php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72159 Imported Class Overrides Local Class Name
Submitted: 2016-05-04 15:24 UTC Modified: 2016-05-04 16:06 UTC
From: rod at owsy dot com Assigned: nikic
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.6 OS: All
Private report: No CVE-ID:
 [2016-05-04 15:24 UTC] rod at owsy dot com
Description:
------------
When importing a class into a namespace it seems to override any classes with that name in the current namespace (PHP 7.0+)

https://3v4l.org/tGv74

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

namespace Foo {

    class Bar
    {
        public $from = 'foo';
    }
}

namespace Bazzle {
    use Foo\Bar;

    class Bar
    {
        public $from = 'bazzle';
    }

    echo (new Bar())->from;
}

Expected result:
----------------
Fatal error: Cannot declare class Bazzle\Bar because the name is already in use

Actual result:
--------------
'foo' is echo'd

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-04 15:33 UTC] nikic@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2016-05-04 16:06 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2016-05-04 16:45 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9af0c96af4ded5ac0935e6cc1a2fa253ce77dfac
Log: Fix bug #72159
 [2016-05-04 16:45 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2016-07-20 11:31 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=9af0c96af4ded5ac0935e6cc1a2fa253ce77dfac
Log: Fix bug #72159
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Apr 30 22:01:36 2017 UTC