Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95347 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94997 invoked from network); 21 Aug 2016 15:46:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2016 15:46:16 -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.192.169 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.192.169 mail-pf0-f169.google.com Received: from [209.85.192.169] ([209.85.192.169:33247] helo=mail-pf0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/14-50790-6CCC9B75 for ; Sun, 21 Aug 2016 11:46:15 -0400 Received: by mail-pf0-f169.google.com with SMTP id y134so24053247pfg.0 for ; Sun, 21 Aug 2016 08:46:14 -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=hMzIWx/Njt2Dy5bK96ArfN7baFOlfpXL2yAOwzwZ5Dk=; b=QHgUofAIWgusyZ+htVqYPe2VxOx+Yf7QHLcuHowob6/d6ONiIjbofgJzNMT0jAcsNf zTTx/JdiMei+mo0uRA1F1JPaDtxHBc4unOt9cEQcHZNA6tGcs6tSEnYDqfAYDuNny31N mDRyBDo7RemzmTJBgi/akztDofwNc8xre+Njd267S4Kq508WgoOmsPSuQj/VczH+3Qjd gwE9ZJYqzAR1BghDs/1Ht80PWXySUNvbbdKc6DCDDnt+2pwAqcgqATLvyXtAGCvmLILa 0sOVIGfnR+HSqhF3HOzcKptIOTS5nHUSP50X9ndRpTHRnydZIJuObq+j7pkBwVwobFNy S0YA== 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=hMzIWx/Njt2Dy5bK96ArfN7baFOlfpXL2yAOwzwZ5Dk=; b=Is8p/9LU5D8fy3qGvZPm9cBvHzYxUcUki/NNFjfxbpXvtGrTrjXouJ2EBMMzJwR57d yTSNuMRHq5j2gAjykAPd+AQYcbR72r5y8MjlJacbIlkvdxBZNY0RjfK2bGBlrwPkLWbr Czu3xRG5h7FHAXVXHdpd8P1zGkfdirqoj9Jv/lDo+Jm542wiR1Ril0bvjc6zC7H4v/yb 1fOrZTpChTI06/P2HP2Fwr8E0L1L5D3IV/1WJJCQswG3TEqluHCU/adqEuInSfTuN76x FNptRfXDhwKlg06mams0cD7OOHPkk6aYVF7o9g5Jp5WviF0v1jbfK0+H+h47utPX8Bmb YsDA== X-Gm-Message-State: AEkoouvAPxHNTSXl+hvCe100PRiGMIEhb3nIrjZJvtxOj7qle1aMLb6YRLExn0jkprWThrcxUnNl9f6ZHw5sBQ== X-Received: by 10.98.33.72 with SMTP id h69mr33997720pfh.28.1471794372448; Sun, 21 Aug 2016 08:46:12 -0700 (PDT) MIME-Version: 1.0 Sender: morrison.levi@gmail.com Received: by 10.66.24.42 with HTTP; Sun, 21 Aug 2016 08:46:11 -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:46:11 -0600 X-Google-Sender-Auth: -pSfRVt4PRBvD8qysIryqMoojVg Message-ID: To: Marco Pivetta Cc: Aaron Piotrowski , internals , Stanislav Malyshev Content-Type: multipart/alternative; boundary=001a113efddec095ff053a96d488 Subject: Re: [PHP-DEV] ReflectionType::__toString() prepending \ to class names From: levim@php.net (Levi Morrison) --001a113efddec095ff053a96d488 Content-Type: text/plain; charset=UTF-8 On Sun, Aug 21, 2016 at 9:42 AM, Marco Pivetta wrote: > Including the question mark still breaks code-gen based on simple nullable > types. PHP 7.0.x-compliant code will do following: > > - reflect function foo(Bar $bar = null) {} > - cast ReflectionType to string > - crash (unrecognized `?` symbol) > > That's part of what I tested on Friday on just one of the many libraries > involved. > > The new API already includes `ReflectionType#allowsNull()`, so that's > sufficient to build forward-compliant codegen. Breaking BC is a no-go > though. > > Marco Pivetta > > http://twitter.com/Ocramius > > http://ocramius.github.com/ > > On Sun, Aug 21, 2016 at 5:39 PM, Levi Morrison wrote: > >> >> >> 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. >> > > If you are on 7.1 and you generate code for an earlier version of PHP that's not really a break... This is the ultimate point: if we don't prepend the question mark it will break code. If do prepend the question mark it will break code. It's a BC break whether it is done or not. So what to do? How to pick which is correct? In my opinion we should preserve the original intention of the code. Thus we should prepend the question mark. --001a113efddec095ff053a96d488--