Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95344 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91477 invoked from network); 21 Aug 2016 15:40:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2016 15:40:02 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=morrison.levi@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.51 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.220.51 mail-pa0-f51.google.com Received: from [209.85.220.51] ([209.85.220.51:32932] helo=mail-pa0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 42/53-50790-15BC9B75 for ; Sun, 21 Aug 2016 11:40:01 -0400 Received: by mail-pa0-f51.google.com with SMTP id ti13so29835702pac.0 for ; Sun, 21 Aug 2016 08:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=4aepTbw/7V3z8a5Nf15yZGLHDK46lDjoMUz7Be5Pr7A=; b=fDnpHcrq916rIjQIsj0acWeWAogZ58ZC+2leglLQPUu2NDNMeWhyCchqyP4hfZInpj 1+7XawRTm0zrii9RXOAX59K37ao7vDFUdGVsobAGq/TepARR8lGQTjEckNRTXFX3ivys Wa+0tqtcySWEipDlz0NuTiTiFqqtNvl9II8uF9Cj9Wln9Gqr0cwO+5B5weS9tQYjtvfV nt/njKOK847O0XPXiViWIl+RSf+AH1BGPVsubpzyeNlMxHErDqZ8k5d8vWxuK6/5dRJ0 rMfdHFhLtiNGrV8FJ/0PGy8BlYPRiAQ+fn9ecKrr/iHPiB9sEQgDpg1JR8xfTbZ9qPxT /Czw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=4aepTbw/7V3z8a5Nf15yZGLHDK46lDjoMUz7Be5Pr7A=; b=QdcpSp1PiQ2KFj/iioQbFTnJC9O2csCIJuG7yaXB7lF7XJvVVt7FKNNSDXDUnZPUG7 NV5enjTE1Q5U486P4j7VxitJSSLzMK96+NKN8yOEM0HphbE3A5apKPVpM/YnWkNg4ukG 9dsLcWA7U2uUZyiLf0WwsXkvdDR4BBro88S4jtSmoKVoamt8gRk4dxSOlKDVL0Z4YBLD YEh1caGXfxR8ZEnDWqxlWaBUh5zhAiTdC5vZYAIZA2o1RjA+hWk37JlU7/DROxzh0/H4 mBm1zSLNbZz+dh/+IlfCX01ALuPMbgCHMC1LFqSByswETfsmhLXxhtDEYIbTNO5fWlWn CvNg== X-Gm-Message-State: AEkoouuiCurSe0gUcevbgxn7nCpFyZ+kndV84fAzB5GRa5imJSiZLXqGAMv+rb9sx1oktowUAaHJoDRnm0oOBg== X-Received: by 10.66.54.132 with SMTP id j4mr33814302pap.110.1471793998675; Sun, 21 Aug 2016 08:39:58 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.66.24.42 with HTTP; Sun, 21 Aug 2016 08:39:57 -0700 (PDT) In-Reply-To: References: <0668D584-EE51-4932-85D7-01D8BF70E409@trowski.com> <15E198DD-FF66-475D-ABBC-54ECD2B6BF62@trowski.com> Date: Sun, 21 Aug 2016 09:39:57 -0600 X-Google-Sender-Auth: M2kwsmdkaUDkDeVL4a1SYKxfNlg Message-ID: To: Aaron Piotrowski Cc: Marco Pivetta , internals , Stanislav Malyshev Content-Type: multipart/alternative; boundary=001a11367696794311053a96be0a Subject: Re: [PHP-DEV] ReflectionType::__toString() prepending \ to class names From: levim@php.net (Levi Morrison) --001a11367696794311053a96be0a Content-Type: text/plain; charset=UTF-8 On Sun, Aug 21, 2016 at 9:07 AM, Levi Morrison wrote: > > > On Sun, Aug 21, 2016 at 8:37 AM, Aaron Piotrowski > wrote: > >> Hi Marco, >> >> > On Aug 19, 2016, at 1:31 PM, Marco Pivetta wrote: >> > >> > 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) >> > >> >> I've reverted the changes so that `ReflectionType::__toString()` is now >> identical to 7.0, including *not* prepending a ? for nullable types. The >> method is now just an alias of `ReflectionNamedType::getName()`. >> >> `ReflectionType::__toString()` should be discouraged for code generation >> going forward, as it seems there's just not a way to add type features in a >> BC way. My attempt to incorporate nullable types in a way that would allow >> for even more complex types such as `callable(?\Type\Name, ?bool)` just >> caused too many problems. >> >> > 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) { >> > } >> >> Only `ReflectionNamedType` was added so the object returned from >> parameter and return types could have a `getName()` method. The rest of the >> RFC was not implemented. This should be completely BC while allowing future >> types like unions or callables. See some discussion here: >> https://github.com/php/php-src/pull/2068 >> >> Aaron Piotrowski >> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > This is too big of a revert. You must attempt to generate exactly what was > written in user code which requires the prepended question mark. > To clarify we do resolve certain things such as names which are aliased by use and the like. But we can't resolve all names such as self and parent because of traits. The use of toString is to dump out the type information in a string that would be suitable for regenerating that exact type declaration only. It is not meant to be parsed or analyzed. It was designed this way from the beginning, and any deviation of this is a misuse. By not prepending the ? we will break other libs, so it's a BC break either way. Please put the question mark back as discussed in the beginning. Do not include the leading slash. --001a11367696794311053a96be0a--