Re: Order of class resolution with namespaces and autoload

From: Date: Tue, 23 Oct 2007 03:55:30 +0000
Subject: Re: Order of class resolution with namespaces and autoload
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  Groups: php.internals 
Request: Send a blank email to internals+get-32925@lists.php.net to get a copy of this message
Quoting Stanislav Malyshev <stas@zend.com>:
import Exception; -> name conflict, which seems correct
import Exception is a no-op, so I don't understand how you could have got name conflict. Do you mean "import Test::Exception"? That should work, if it didn't it's a bug.
It turns out that this does not happen with CVS PHP 5.3. With Greg's first patch for fixing multiple uses of import Test::Exception, however, this is the reproduce script and error: <?php namespace Foo; import Exception; results in: Maya:/tmp chuck$ php import_exception.php Fatal error: Import name 'Exception' conflicts with defined class in /private/tmp/import_exception.php on line 4 Also, with unpatched 5_3 CVS, I get this: Warning: The import statement with non-compound name 'Exception' has no effect in /tmp/import_exception.php on line 4 I think that either import ::Exception needs to work, or import Exception shouldn't issue a warning.
import Exception as Error; -> Fatal error: Import name 'Error' conflicts with defined class in /Users/chuck/Desktop/php namespaces/2.php on line 4 (this I don't understand)
I'm afraid I am missing something since in line 4 of 2.php there's no definition of any class or import. Can you give me full examples of non-working parts? It might be there's some bug in there.
This is another one that only happens with Greg's initial patch (I haven't tried the next one yet Greg, sorry). For Greg's benefit here's the reproduce script: <?php namespace Foo; import Exception as Error; And result: Maya:/tmp chuck$ php import_exception_alias.php Fatal error: Import name 'Error' conflicts with defined class in /private/tmp/import_exception_alias.php on line 4
import ::Exception as Error; -> parse error (can't import a top-level class name that way)
Well, we might allow importing global classes, if it's needed.
I think this would be a good thing.
Therefore, in my mind, in order to write durable code that will not break no matter what other classes other developers define or import, I should always prefix builtin classes with ::.
Other developers shouldn't define or import classes into your namespace...
I think you need to envision working in a large team on a large project here, but you may simply not see the need. -chuck

« previous php.internals (#32925) next »