Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62996 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66914 invoked from network); 14 Sep 2012 08:08:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Sep 2012 08:08:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.199.177.89 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 212.199.177.89 il-mr1.zend.com Received: from [212.199.177.89] ([212.199.177.89:50993] helo=il-mr1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/88-31416-2F5E2505 for ; Fri, 14 Sep 2012 04:08:21 -0400 Received: from il-gw1.zend.com (unknown [10.1.1.22]) by il-mr1.zend.com (Postfix) with ESMTP id 6139760764; Fri, 14 Sep 2012 11:01:33 +0300 (IDT) Received: from tpl2.home (10.1.10.10) by il-ex2.zend.net (10.1.1.22) with Microsoft SMTP Server (TLS) id 14.1.255.0; Fri, 14 Sep 2012 11:08:09 +0300 Message-ID: <5052E5EC.2030103@zend.com> Date: Fri, 14 Sep 2012 12:08:12 +0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: Ralph Schindler CC: internals References: <504F4D33.4070306@ralphschindler.com> <5051968E.7030908@zend.com> <5052474B.5050706@ralphschindler.com> In-Reply-To: <5052474B.5050706@ralphschindler.com> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.1.10.10] Subject: Re: [PHP-DEV] [VOTE] ::class feature to resolve namespaced class names to scalars From: dmitry@zend.com (Dmitry Stogov) Hi Ralph, You persuade me. :) The SOMETHING::class syntax looked wired to me because I didn't understand it. However, the SOMETHING::class syntax might be considered as a reference to a predefined class constant and in this case it looks quite consistent. I suggest to reflect it in RFC and documentation (if we agree to include it in release) to avoid future misunderstanding. Also I would expect SOMETHING::class to work in all cases where class constants work. e.g. self::class, parent::class, static::class, $obj::class. To do it for parent, static and $obj you'll probably need a new opcode - ZEND_FETCH_CLASSNAME that must be very similar to ZEND_FETCH_CLASS. May be it's possible to do the same using ZEND_FETCH_CONSTANT, but I don't think it makes sense to complicate the existing opcode. SOMETHING::class must be consistent with traits. In case all the above works, I say +1 and even may help with implementation. Finally, may be SOMETHING::__CLASS__ is a bit more clear than SOMETHING::class. Thanks. Dmitry. On 09/14/2012 12:51 AM, Ralph Schindler wrote: > >> I think the syntax is wired. >> Instead of classname::class I would prefer something like >> class(classname). >> > > I am not a big fan of the syntax class(ShortClass\Name) as to me it > looks like a function call. > > Personally, I like drawing parallels from the same languages that I > think helped shaped PHP's object-model. In this case, the Java has a > similar enough feature where Type.class returns a class object (in our > case we just need to return a string of the FQ class name). > > Your suggestion is similar to that of, I think, C# where > typeof(SomeClassName) would return a reflection-like/type object where > you could get the FullName(): > > http://msdn.microsoft.com/en-us/library/58918ffs%28v=vs.71%29.aspx > > I could go either way, at this point (after the April discussion on the > matter), I had not really given much thought to class() lang. construct. > > Personally, ::class feels a bit better to me in that the context feels > more "compile-time", like __CLASS__, and the NS resolutions, than does > class() that you suggest. > > From a wider perspective, I've seen these variations in the wild: > > class Foo { > const CLASSNAME = __CLASS__; > // or > const _class = __CLASS__; > } > > Which allows for the usage: > > Foo::CLASSNAME; > > for example. > > FWIW, both reusing the class() keyword making it BC, which is something > I like. > > -ralph > >