Re: New Feature: Fully qualified class name resolution as scalar with class keyword
| From: | Simon Schick | Date: | Mon, 16 Apr 2012 13:15:58 +0000 |
| Subject: | Re: New Feature: Fully qualified class name resolution as scalar with class keyword | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-59999@lists.php.net to get a copy of this message | ||
2012/4/16 Ralph Schindler <ralph@ralphschindler.com>
>
> ... PHP does not invoke the autoloader to determine if the class name
> actually exists as a declaration somewhere, it simply resolves it according
> to some very specific rules (in the case of this patch, carried out by
> zend_resolve_class_name()).
>
> If I am within a namespace and am using a short name without a preceding
> "\", it means the class I am referencing exists in the current namespace.
> Whether or not that class exists is irrelevant as my short name can only
> mean "a class by this name in the current namespace". In this code:
>
> namespace Foo\Bar {
> global $foo;
> if ($foo && $foo instance Bar) {
> // ...
> }
> }
>
> ... that you, the developer, intend that your reference to Baz actually
> means "Foo\Bar\Baz", it can never mean anything else.
>
> So, in a nutshell, there is no guessing going on ;)
> -ralph
Hi, Ralph
Agree on that. I'd like to have a comment in the test, specially for
this line where you're checking for non-existing classes. It does not
seem to be obvious what should be tested here (at least it was not
obvious for me). This may make it easier to fix stuff if this test
should fail in future.
I don't know if this here is the right test to put the comment in, but
it's at least relying on something global that may change.
Thanks for giving me a deeper knowledge here :)
Bye
Simon