On Sat, Apr 14, 2012 at 12:50 PM, Ralph Schindler
<ra...@ralphschindler.com>wrote:

> Hi all,
>
> There are many different use cases were in code we expect classes names as
> arguments to functions as fully qualified names.  We do this in ZF a lot
> with our Service Location and DI components, but also with our code
> reflection API, etc.  A more interesting use case I would like to call out
> is with PHPUnit, for example in a test, you might find this:
>
>  $mock = $this->getMock('A\Namespaced\**ClassName');
>
> [...]
>
>
> This overloads the "class" keyword, and by virtue of the existing usage of
> "class" this feature is completely backwards compatible.  All existing
> tests pass.  For example, the above PHPUnit snipped would become:
>
> Would it be easy to have a patch that simply allows use of the class name,
or is the "::class" suffix necessary to resolve some ambiguity? Example
usage:

    $mock = $this->getMock(A\Namespaced\**ClassName);
    # or
    use A\Namespaced\ClassName;
    $mock = $this->getMock(ClassName);

Would changing the definition for class_name_scalar be sufficient?

    class_name_scalar:
        class_name { zend_resolve_class_name(&$1, ZEND_FETCH_CLASS_GLOBAL,
1 TSRMLS_CC); $$ = $1;  }
    ;

To my eye, this is the least surprising syntax.

Reply via email to