Hey Simon,

As the class-definition for Moo is missing, I think it's an empty
class (like Baz) on the root-level defined somewhere else, right?
Otherwise this should do something else than guessing the class-name.

If you look at the patch, this feature is not doing anything PHP doesn't already do in other circumstances - demonstrated by the fact that its only about 4 lines of code ;)

In PHP, in situations like (instanceof):

  if ($foo instanceof Bar)

or (catch)

  } catch (SomeException $e) {

or (method signature)

  public function setFoo(FooInterface $foo)

... 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

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

Reply via email to