Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66233 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67196 invoked from network); 26 Feb 2013 09:08:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2013 09:08:26 -0000 Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 213.123.20.131 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 213.123.20.131 c2bthomr13.btconnect.com Received: from [213.123.20.131] ([213.123.20.131:61332] helo=mail.btconnect.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B0/51-57982-88B7C215 for ; Tue, 26 Feb 2013 04:08:25 -0500 Received: from host81-138-11-136.in-addr.btopenworld.com (EHLO _10.0.0.5_) ([81.138.11.136]) by c2bthomr13.btconnect.com with ESMTP id KXC40273; Tue, 26 Feb 2013 09:08:20 +0000 (GMT) Message-ID: <512C7B84.7040405@lsces.co.uk> Date: Tue, 26 Feb 2013 09:08:20 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 SeaMonkey/2.15 MIME-Version: 1.0 To: "internals@lists.php.net" References: <01F30F77-B22D-40CE-ADF1-AC1C488FE39D@me.com> <5F87647B-339F-48A1-82B3-E210F95766CD@me.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0301.512C7B84.0012, actions=tag X-Junkmail-Premium-Raw: score=7/50, refid=2.7.2:2013.2.26.83322:17:7.944, ip=81.138.11.136, rules=__MOZILLA_MSGID, __HAS_MSGID, __SANE_MSGID, __HAS_FROM, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __TO_MALFORMED_2, __TO_NO_NAME, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, URI_ENDS_IN_PHP, __ANY_URI, __FRAUD_BODY_WEBMAIL, __C230066_P3_2, __CP_URI_IN_BODY, BODY_ENDS_IN_URL, __FORWARDED_MSG, BODY_SIZE_4000_4999, __MIME_TEXT_ONLY, RDNS_GENERIC_POOLED, HTML_00_01, HTML_00_10, BODY_SIZE_5000_LESS, RDNS_SUSP_GENERIC, RDNS_SUSP, __FRAUD_WEBMAIL, BODY_SIZE_7000_LESS X-Junkmail-Status: score=10/50, host=c2bthomr13.btconnect.com X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B0209.512C7B84.00ED:SCFSTAT14830815,ss=1,re=-4.000,fgs=0, ip=0.0.0.0, so=2011-07-25 19:15:43, dmn=2011-05-27 18:58:46, mode=multiengine X-Junkmail-IWF: false Subject: Re: [PHP-DEV] Late FQCN resolution using ::class From: lester@lsces.co.uk (Lester Caine) This is an interesting discussion, and since I use phpdoc extensively, it's an area that I have been thinking about, but WHY do you have to make it so difficult to follow by simply bundling more text at the top. THIS needs to be quoted properly and THEN perhaps other people can follow the discussion. Try reading the rest of this message when you don't know what came before !!!!! 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). > > 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). > > 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. > > On Tue, Feb 26, 2013 at 8:25 AM, Jens Riisom Schultz wrote: > >> Ok I get that, thankyou for the explanation. >> >> 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?) >> >> 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. >> >> -Jens >> >> On Feb 25, 2013, at 11:20 AM, Nikita Nefedov wrote: >> >>> 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 = '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 = "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. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk