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 (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.6 OS: All
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: rod at owsy dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC