Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95322 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50304 invoked from network); 19 Aug 2016 18:32:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Aug 2016 18:32:19 -0000 Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:37985] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/B4-17996-1B057B75 for ; Fri, 19 Aug 2016 14:32:18 -0400 Received: by mail-wm0-f42.google.com with SMTP id o80so53247868wme.1 for ; Fri, 19 Aug 2016 11:32:17 -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 :cc; bh=TromKcSOLiHyUwCHEu9j2CncbVqFSq07bIFV+ufG8n4=; b=u0aBpEbGbTcx7BR2G/TccKtYrVhvlGrGphHq0Ec9iSQPUBAnTSTF8zi62EHs6WaVZ3 qDtc3FOWoPbJqj3UE6dHJlimVAJWUbvUTfM8c+kjSnzO/J74OWhJg4lm4dx/v1SyXap3 7mrjYKohbVoCVmcz9AhguWC7Q+2S0tC/whRizCzj1rHXV5YScneaUxYC9BK9XZxRPflX nR8cJyY/CYtGeTywojCgR7sGqvktx3u/vev6kXF+nkkNbNgnR2uudTiX7ptasSUixwUn ctccwzWVh64Bzl83R4BNLnhfj4ZE/S55RbkJpJ4VB3RJNkquTQreOv5YelHWJ8yb2Ptw 2CYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TromKcSOLiHyUwCHEu9j2CncbVqFSq07bIFV+ufG8n4=; b=gWrPWGyPCZGyKvLHoBq7PMvzXDm+EdVUlUNo8sBuLZDgtEi10jeaxX00kD7P2kKTBX GHC4LWS8h0BaLsRYQwMOkYO0nWHAMmJSGkmx3yzwMu+bXtBhJ5N/Gr4Ue6s89HHDnrb5 LBAH7kUebfltnzCC/yiJtj2YNcL4mw2i2qfg40sdOa5vTuJiLc7HwXctj5CKjMLYwQc+ DYkTbaWbWzQgvP0TlZqjrDHjHCT7ehfVDB+vh6kAbHDXjpHtaGp3w7GLd86ZMHjMMvlF XTzoe88R1mjouZHIbeJWX9OrYofqmn/TYS2URAnCWhhYvM1u2aRbk7Y5w7jhGU75UMub 3CYg== X-Gm-Message-State: AEkooutZA7qJ4E3Tuti4CHePHGKVdB/naYd8qYZlRD9ONRJSK4bvMezNL1CJ1Dl5EgwKLMF4OFjD513djXuE3g== X-Received: by 10.28.27.211 with SMTP id b202mr5324985wmb.12.1471631534676; Fri, 19 Aug 2016 11:32:14 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.125.242 with HTTP; Fri, 19 Aug 2016 11:31:53 -0700 (PDT) In-Reply-To: References: <0668D584-EE51-4932-85D7-01D8BF70E409@trowski.com> <15E198DD-FF66-475D-ABBC-54ECD2B6BF62@trowski.com> Date: Fri, 19 Aug 2016 20:31:53 +0200 Message-ID: To: Aaron Piotrowski Cc: internals Content-Type: multipart/alternative; boundary=001a114b3ab8dd63cd053a70ea05 Subject: Re: [PHP-DEV] ReflectionType::__toString() prepending \ to class names From: ocramius@gmail.com (Marco Pivetta) --001a114b3ab8dd63cd053a70ea05 Content-Type: text/plain; charset=UTF-8 Hi Aaron et all, I tried to implement support for 7.1 in zend-code as a start: https://github.com/zendframework/zend-code/pull/87 A few issues arise: * `ReflectionType#__toString()` is too volatile, especially if we want to support multiple versions of PHP, therefore it's a good idea to not think too much about it, and instead deprecate it. Most issues I had while working with the feature were related with string formatting, and that's simply gotta die: just using a more specific API should cut it (getName, getClass, isNullable, etc. As few strings as possible, please!). * A page where we can see the current state of the `ReflectionType` API (and its subtypes) would be golden. * `ReflectionType#__toString()` seems to crash in very interesting ways when `?string` is reflected (see issue above - couldn't isolate precisely) Cheers, Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On Fri, Aug 19, 2016 at 7:16 PM, Marco Pivetta wrote: > Hey Aaron, > > I am currently going through the changes, and just figured that 7.1 > implements https://wiki.php.net/rfc/reflectiontypeimprovements, even > though the RFC was declined: > > ./sapi/cli/php -r 'class Foo { public function bar() : ?Foo {} } > var_dump((new ReflectionMethod("Foo", "bar"))->getReturnType());' > object(ReflectionNamedType)#2 (0) { > } > > Was there a newer RFC that I missed? > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > > On Wed, Aug 17, 2016 at 7:25 PM, Marco Pivetta wrote: > >> On Wed, Aug 17, 2016 at 7:17 PM, Aaron Piotrowski >> wrote: >> >>> >>> > On Aug 17, 2016, at 12:02 PM, Marco Pivetta >>> wrote: >>> > >>> > That would have been a headache anyway. We saw it coming, and it will >>> be fixed on our end, but please don't try to outsmart it. >>> > I know that there is good intention on your side, but this is really >>> going to just make it an issue. >>> >>> Looks like this problem is more complicated than I thought. I thought >>> prepending the \ would mean little work on your end, but it appears I was >>> wrong. >>> >>> I'm still confused as to what's going on and what the best solution >>> is... Currently Doctrine is manually prepending \ to class names. Obviously >>> your logic would have to change between 7.0 and 7.1, but then going forward >>> you could rely on ReflectionType::__toString() to return a syntax-valid >>> type name, rather than modifying it. Or perhaps rather than relying on >>> casting to a string and examining the string, Doctrine should be using >>> ReflectionNamedType::getName() and ReflectionType::allowsNull() for 7.1 and >>> beyond. (Just a suggestion, I'd have to dig into the code to really >>> understand what's going on, and I don't have a ton of time to do so at the >>> moment.) >>> >> >> The problem is that we're not talking about 1 library, but a few (and I'm >> only talking about the ones I know of). >> Changing behavior is going to cause issues. >> >> >>> > From the codegen-side (I do write a lot of code generators), having >>> `\` prepended in front of stuff makes things just more complex to deal >>> with, since I have to strip it and re-introduce it anyway in multiple >>> locations in the code, while it should just be attached in the final >>> output-logic bit. >>> > Instead, please keep the reflector on-spot: reflecting things, telling >>> us what they are. What the code generator does with the definitions is up >>> to the code generator after that. >>> > >>> > We have to adjust the code for `void` and `?` anyway, so this is just >>> more changes to keep track of, and it would break existing code. >>> >>> It sounds like you'd prefer the ? was not prepended to the string as >>> well, is that correct? Again it sounds like it would be better to use >>> methods other than __toString(). I understand __toString() was the only way >>> to get the type name before, but now that this has been fixed perhaps it >>> should be avoided in your use-cases. >> >> >> I think that adding the `?` would be semantically correct, from a >> reflector perspective (remember, we are only reflecting: please completely >> ignore the idea of using this for codegen, it is a separate domain). >> >> I can't tell you for sure right now, but I will check on Friday. >> >> Libraries that directly affect me personally are doctrine/common, >> zendframework/zend-code and ocramius/proxy-manager, so I am only talking >> about these 3 for now. >> If I remember correctly, in all three a `(string)` cast is being used for >> discovering scalar types, although I am not sure. >> >> Can you please poke me at EOD on Friday, so maybe we look at this >> together? >> >> Cheers, >> >> Marco Pivetta >> >> http://twitter.com/Ocramius >> >> http://ocramius.github.com/ >> >> > --001a114b3ab8dd63cd053a70ea05--