Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66314 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69931 invoked from network); 28 Feb 2013 07:03:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2013 07:03:19 -0000 Authentication-Results: pb1.pair.com header.from=ibmurai@me.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ibmurai@me.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain me.com designates 17.158.232.237 as permitted sender) X-PHP-List-Original-Sender: ibmurai@me.com X-Host-Fingerprint: 17.158.232.237 nk11p03mm-asmtpout002.mac.com Solaris 10 1203 Received: from [17.158.232.237] ([17.158.232.237:50205] helo=nk11p03mm-asmtp002.mac.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/E0-63468-5310F215 for ; Thu, 28 Feb 2013 02:03:18 -0500 Received: from [192.168.1.64] (188-182-36-146-static.dk.customer.tdc.net [188.182.36.146]) by nk11p03mm-asmtp002.mac.com (Oracle Communications Messaging Server 7u4-26.01(7.0.4.26.0) 64bit (built Jul 13 2012)) with ESMTPSA id <0MIX00DO94XAK5A0@nk11p03mm-asmtp002.mac.com> for internals@lists.php.net; Thu, 28 Feb 2013 07:03:14 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327,1.0.431,0.0.0000 definitions=2013-02-28_01:2013-02-28,2013-02-28,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=2 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1302270358 Content-type: multipart/alternative; boundary="Apple-Mail=_8E363B08-4690-4A2D-9C37-78F54F3D0498" Message-ID: <47B51A20-0EEC-476C-967A-420A68425160@me.com> MIME-version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Date: Thu, 28 Feb 2013 08:03:12 +0100 References: <01F30F77-B22D-40CE-ADF1-AC1C488FE39D@me.com> <5F87647B-339F-48A1-82B3-E210F95766CD@me.com> To: Benjamin Eberlei , "internals@lists.php.net" In-reply-to: X-Mailer: Apple Mail (2.1499) Subject: Re: [PHP-DEV] Late FQCN resolution using ::class From: ibmurai@me.com (Jens Riisom Schultz) --Apple-Mail=_8E363B08-4690-4A2D-9C37-78F54F3D0498 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=iso-8859-1 On Feb 26, 2013, at 10:00 AM, Benjamin Eberlei = wrote: > This is indeed not possible, because strings are not class context = independent, you can pass them to anywhere. A string just doesn't know = what namespace it belongs to and this does not make sense without = providing more context in client libraries (such as docblocks). >=20 > Also the use statement information is NOT available in the engine, = because its resolved way before in the compiling step (as far as i = understood it). Thankyou for clarifying this. It was really all I wanted to know. I guess this discussion is dead (though it birthed a different = discussion, which is also impossible to follow since it is laced with = flames) I'm pulling out of this one. Thankyou all. >=20 > What Doctrine Annotations does to solve this is parsing this = information ourselves, using token_get_all(), then caching this = information on a per file basis. >=20 >=20 > On Tue, Feb 26, 2013 at 8:25 AM, Jens Riisom Schultz = wrote: > Ok I get that, thankyou for the explanation. >=20 > static::class is not an option. I'm trying to resolve class names = defined in docblocks, since phpdoc2 allows for entering type hints = (classes) as namespace/use relative. And I can tell there is no current = way of resolving class names in strings, to FQCN's, unless I'm missing = something? (There is no way to get a list of the currently used = namespaces as far as I can tell - would such a function be possible to = add to the SPL, without any major rewriting?) >=20 > So, I'm simply wondering if this would require any major rewriting to = support? Otherwise I could look into it and try to write a patch... = Because I think this would be really useful for framework developers, = php unit testing and php doc for example. >=20 > -Jens >=20 > On Feb 25, 2013, at 11:20 AM, Nikita Nefedov = wrote: >=20 > > On Mon, 25 Feb 2013 14:00:04 +0400, Jens Riisom Schultz = wrote: > > > >> Hi everybody, > >> > >> I have read up on this, and done some testing. > >> > >> First up, my findings with PHP5.5 alpha5: > >> > >> >> namespace spacy; > >> > >> class classy { > >> public static function fqcn() { > >> /* This works but is not useful enough: */ > >> //return self::class; > >> > >> $me =3D 'classy'; > >> > >> /* This just doesn't work, but I wish it did: */ > >> //return $me::class; > >> > >> /* This simply does not work as expected: */ > >> return eval("return $me::class;"); > >> /* Output: "classy" - Expected output: = "spacy\classy" */ > >> } > >> } > >> ?> > >> > >> I'm trying to late resolve a class name contained in a variable to = the FQCN. I understand that this is hard (maybe even impossible) with = the current implementation, because class name resolution happens = compile time, but eval("return $me::class;") simply returns something = that is weird. > >> > >> I guess what I'm trying to ask is whether it would be impossible to = support late FQCN resolution in any way? It would be very useful for = frameworks to be able to do this. > >> > >> - Jens Riisom Schultz > >> -- > >> PHP Internals - PHP Runtime Development Mailing List > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > > > > Hi Jens, > > > > Here's what happened in your code: > > When you invoked fqcn(), you created var $me =3D "classy"; > > Then you tried to invoke this code in eval: "return classy::class;" > > But when php evals code, it's like including another file. So it = executes the code without any namespace (it's in global namespace), and = php didn't discover class with name classy (there's only spacy\classy) = yet, so it tries to resolve all your "use" statements (but you didn't = write any) and then just gives you "classy", it didn't throw any error = just because it tried to delay autoloading of this class as far as = possible, if would do eval("return new $me;") then you would get fatal = error. >=20 >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20 --Apple-Mail=_8E363B08-4690-4A2D-9C37-78F54F3D0498--