Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66234 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69788 invoked from network); 26 Feb 2013 09:36:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2013 09:36:00 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 74.125.82.182 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 74.125.82.182 mail-we0-f182.google.com Received: from [74.125.82.182] ([74.125.82.182:64603] helo=mail-we0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 84/B1-57982-EF18C215 for ; Tue, 26 Feb 2013 04:35:59 -0500 Received: by mail-we0-f182.google.com with SMTP id t57so3375835wey.27 for ; Tue, 26 Feb 2013 01:35:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:x-originating-ip:in-reply-to:references :date:message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=SW5rg1Dzf655iyh6Y6ONPIt5SAdxwcjgbNuYWbb3E8k=; b=pvQb+hX7F0O9Db9TayB1mdv+KklMkc+cOhb8bQIugZG+1INh+7jX/Hj7Nh9DfRqY66 gddHep9tfNYKQoDwkeoKYP8wkJtn6yHtzIuPgZKbSDfcgOBEeCrrJp5izVkNJy3jZPIb T7dvjByObCZev2BqF06tkzjvikAkkyXysY0fnNP2JcNqoNt0APlUe6+FaBT0DqZUQAwx 746aB6GxYaJ/2hWKvBTicrKQjGGY1IKgq4qnjCRGu+p58nqqP577IQ4a7W6jzc7w1cnn omV9h7Yr2qlYByRBdbMfLhQMj27/sjJcRuPrBs88xr4aAAEUnvMNDMNiHCyKanvkr0sy qj/g== MIME-Version: 1.0 X-Received: by 10.180.73.238 with SMTP id o14mr17734833wiv.32.1361871355246; Tue, 26 Feb 2013 01:35:55 -0800 (PST) Received: by 10.194.5.233 with HTTP; Tue, 26 Feb 2013 01:35:55 -0800 (PST) X-Originating-IP: [77.13.223.70] In-Reply-To: <512C7B84.7040405@lsces.co.uk> References: <01F30F77-B22D-40CE-ADF1-AC1C488FE39D@me.com> <5F87647B-339F-48A1-82B3-E210F95766CD@me.com> <512C7B84.7040405@lsces.co.uk> Date: Tue, 26 Feb 2013 10:35:55 +0100 Message-ID: To: Lester Caine Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d043c80da5c160b04d69d62e6 X-Gm-Message-State: ALoCoQkDXwJ+yXMkYmJXSEPVbaKrB/4p56yr0Cmhi0K+g1Yq7i1gIBjeduaOl0Sj/9bArIJyyeK6 Subject: Re: [PHP-DEV] Late FQCN resolution using ::class From: kontakt@beberlei.de (Benjamin Eberlei) --f46d043c80da5c160b04d69d62e6 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Feb 26, 2013 at 10:08 AM, Lester Caine wrote: > 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 !!!!! Sorry, forgot to post inline. Thanks for mentioning it and doing it wrong yourself, made me laugh ;-) But you are right. > > > 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 > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d043c80da5c160b04d69d62e6--