From:             greg at chiaraquartet dot net
Operating system: linux
PHP version:      5CVS-2007-10-05 (CVS)
PHP Bug Type:     Scripting Engine problem
Bug description:  import always conflicts with internal classes

Description:
------------
zend_do_import incorrectly compares an import name to global class names. 
It should compare EG(current_namespace) . '::' . importname to check for
conflicting names.

This is because when inside a namespace, to the user, import should behave
in the same manner as a class declaration.  This code:

<?php
namespace Foo;
class Exception {}
?>

creates Foo::Exception.

This code:

<?php
namespace Foo;
import Blah::Exception as Exception;
?>

Should essentially work as if the user had typed:

<?php
namespace Foo;
import Blah::Exception as Foo::Exception;
?>

In other words, it should resolve future uses of "Exception" to
"Blah::Exception" and "::Exception" to "Exception" and not complain about
"Exception" conflicting with "::Exception"

Patch for PHP 5:
http://pear.php.net/~greg/fix_import.patch.txt
Patch for PHP 6:
http://pear.php.net/~greg/fix_import.php6.patch.txt

Reproduce code:
---------------
testme.php:
<?php
namespace Blah;
class Exception extends ::Exception {}
?>

test.php:
<?php
namespace Foo;
include 'testme.php';
import Blah::Exception;
$a = new Exception;
throw $a;
?>



Expected result:
----------------
Fatal error: Uncaught exception 'Blah::Exception' in
/home/cellog/workspace/php5/test.php:5
Stack trace:
#0 {main}
  thrown in /home/cellog/workspace/php5/test.php on line 5


Actual result:
--------------
Fatal error: Import name 'Exception' conflicts with defined class in
/home/cellog/workspace/php5/test.php on line 4


-- 
Edit bug report at http://bugs.php.net/?id=42859&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42859&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42859&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42859&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42859&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42859&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42859&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42859&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42859&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42859&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42859&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42859&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42859&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42859&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42859&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42859&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42859&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42859&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42859&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42859&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42859&r=mysqlcfg

Reply via email to