Bug #70135 [NEW]: class alias conflict with class defined in another file with the same namespace

From: Date: Sat, 25 Jul 2015 16:08:32 +0000
Subject: Bug #70135 [NEW]: class alias conflict with class defined in another file with the same namespace
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194705@lists.php.net to get a copy of this message
From:             php at lvht dot net
Operating system: linux & mac os x
PHP version:      5.6.11
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:class alias conflict with class defined in another file with the same namespace

Description:
------------
In one file with a namespace(eg, Lv), we define a class named Foo.

In another with a subnamespace(eg, Lv\Common), we define another class
with the *same* name Foo. 

In the third file with the same namespace(Lv), we first "import"
Lv\Common\Foo using "use Lv\Common\Foo" and then define a class named
Bar that extends Foo(the Lv\Common\Foo).

In a test file, we first make an instance of Lv\Foo, and then try to
make an instance of Lv\Bar, which will failed with a fatal error.

Test script:
---------------
We need four files in the same directory.

1. In Foo.php,

<?php namespace Lv;
class Foo{}

2. In CommonFoo.php,

<?php namespace Lv\Common;
class Foo{}

3. In Bar.php,

<?php namespace Lv;
require 'CommonFoo.php';
use Lv\Common\Foo;
class Bar extends Foo {}

4. Finally, in app.php,
<?php
require 'Foo.php';
$foo = new Lv\Foo;
require 'Bar.php';
$bar = new Lv\Bar; # error will trigged by this line

Just run php app.php, you will see a fatal error.


Expected result:
----------------
The app.php should run without any error.

Actual result:
--------------
The error given,

PHP Fatal error:  Cannot use Lv\Common\Foo as Foo because the name is
already in use in ...Bar.php  on line 3

-- 
Edit bug report at https://bugs.php.net/bug.php?id=70135&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70135&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70135&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70135&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70135&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70135&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70135&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70135&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70135&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70135&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70135&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70135&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70135&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70135&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70135&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70135&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70135&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70135&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70135&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70135&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70135&r=mysqlcfg



Thread (5 messages)

« previous php.bugs (#194705) next »