Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60103 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69544 invoked from network); 17 Apr 2012 19:37:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Apr 2012 19:37:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=ww.galen@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ww.galen@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: ww.galen@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:52521] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 67/83-03996-676CD8F4 for ; Tue, 17 Apr 2012 15:37:27 -0400 Received: by yenl5 with SMTP id l5so3738928yen.29 for ; Tue, 17 Apr 2012 12:37:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=6chZyxGby1p8LViBNEY7OrYP8UH27RQdv3n5h4b8GBQ=; b=XmTFbWpqvh0qfi6kIMuSNsQWWC4NXxHAkBJIKc46Qkfvb/jlauxxsa7eA4Lcf2I0v4 EAMbTS6URNOVMMSDfZibR8RXPqrN4hHmFgt0iIu0PSxCczP+CfjtnTKe+9IYoW8dAAk9 geC4ABCpxT4JVzMbKScPumejnQEZntfE7nf/8CzzgDPgOJx0f6gOXofDRAqawKfkczmy 3d6qsDdd56Rq2An87EgEOGT4NiEl34HLcHVhjI7L/o/lAFyVIwMJXifECdE8lab1x504 78hzH4vAQtqDJAu+Mxk4f2Qg64XB6zNG8uOZqKPRAcM6uJEY1GeqHfgOPu8d9hWR0zjL bxsw== Received: by 10.50.222.162 with SMTP id qn2mr10839891igc.65.1334691443464; Tue, 17 Apr 2012 12:37:23 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.144.201 with HTTP; Tue, 17 Apr 2012 12:36:43 -0700 (PDT) In-Reply-To: References: <4F89D4F1.8070009@ralphschindler.com> Date: Tue, 17 Apr 2012 12:36:43 -0700 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=14dae9340fbf5f59fd04bde5119a Subject: Re: [PHP-DEV] New Feature: Fully qualified class name resolution as scalar with class keyword From: ww.galen@gmail.com (Galen Wright-Watson) --14dae9340fbf5f59fd04bde5119a Content-Type: text/plain; charset=ISO-8859-1 On Sat, Apr 14, 2012 at 12:50 PM, Ralph Schindler 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. --14dae9340fbf5f59fd04bde5119a--