David Grudl wrote:
> -------- Původní zpráva --------
> Předmět: Re:Namespace resolution rules has been changed?
> Od: David Grudl <[EMAIL PROTECTED]>
> Datum: 10.11.2008 23:53
>> > Can you please point us to an example describing this best practice?
>>
>> For example Namespace Naming Guidelines in .NET
>> (http://msdn.microsoft.com/en-us/library/893ke618(VS.71).aspx)
>>
>> "A nested namespace should have a dependency on types in the
>> containing namespace. For example, the classes in the
>> System.Web.UI.Design depend on the classes in System.Web.UI. However,
>> the classes in System.Web.UI do not depend on the classes in
>> System.Web.UI.Design."
>>
>> Or Zend Framework source code. There is no class extending class from
>> subpackage (class Zend_View extends Zend_View_Abstract is not
>> subpackage, viz
>> http://framework.zend.com/wiki/display/ZFPROP/Naming+conventions+for+2.0+-+Matthew+Ratzloff).
>>
>> *
>> *
> 
> And another example is Nette Framework, maybe the first PHP framework
> ready to use namespaces. Nowhere in the code is the place where
> "relative qualification" would be useful. On the contrary,  in all
> places you is needed "full qualifications". Obligation to use the slash
> is just a pain.

Hi,

let's look at this code:

<?php
namespace foo\classes;
class buh extends foo\stuff {}
?>


There are a few things to keep in mind.  PHP has __autoload(), which C#
does not have.  Thus, a solution such as:

1) try foo\classes\foo\stuff
2) try foo\stuff

does not work because we get double-autoload call for foo\stuff, which
is a hidden performance penalty.  This means we can't quietly resolve
qualified class names as if they were fully qualified and continue to
support the other method.

In addition, in spite of your examples, this is a common language
principle, and I found that both C++ and C# have clear examples in their
manuals of similar resolution rules to what PHP has.  They use it for
accessing sub-namespaces:

http://www.java2s.com/Tutorial/Cpp/0020__Language-Basics/Anestednamespace.htm
http://msdn.microsoft.com/en-us/library/z2kcy19k(VS.80).aspx

In addition, C# has a disambiguation method for specifying fully
qualified class name when there is another name that conflicts in the
namespace: prefix "global::" to it.

http://msdn.microsoft.com/en-us/library/c3ay4x3d(VS.80).aspx

Obviously, prepending a single backslash is far preferable to something
like prepending "global::".

Finally, as a last point, you will have to prepend \ to all global
classes anyways (and this can't be changed), how is this any different
from prepending \ to class names that are\like\this?  We introduce a
language inconsistency by treating short and long names arbitrarily
differently, especially because import rules are applied to *all*
qualified names unless they start with \.  For instance:

<?php
namespace foo\classes;
use sneaky\devil as foo;

class buh extends foo\stuff {}
\\ this extends sneaky\devil\stuff. oops... should have used \foo\stuff
?>

Greg

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to