Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95345 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92938 invoked from network); 21 Aug 2016 15:42:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2016 15:42:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; 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:37439] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/A3-50790-FFBC9B75 for ; Sun, 21 Aug 2016 11:42:55 -0400 Received: by mail-wm0-f42.google.com with SMTP id i5so108154286wmg.0 for ; Sun, 21 Aug 2016 08:42:55 -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=m7Hd05J+bWze+B+q+mfSPN9KASeTAnUU6hy635H8y2M=; b=p0hw5lma62pGMO100ykFaokGWUTY9F+7kN1Ri4c4q56OeP1ojk3RtDAIsstNsj0+W1 OiiP9kt7iEjE3qvihegHiHELFHQV8X1fUGb7H2CcaA7cs5MSlgLgT5Se9NQt21Y7at+V /2W8EDDOoxbxv26VrhNTzGuRHnECVRFwQIz8ms2Q+l0ezHtFX0RuQA4hCFb14CfzsKt7 52ZI5nHZ0af5BTPXlb0w79bX/86+Gv+uQaVW298g6JvD7c7vNeXdYcDOeVLjX40ecnsG RjrTDgJD0KULni3WvZgSy3NgXJKYicZl7ms4amPtmGE1AKUUW7bPAbd+Uf7Z+iiM/+ns vUsg== 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=m7Hd05J+bWze+B+q+mfSPN9KASeTAnUU6hy635H8y2M=; b=Dwii/k39N9onSfD7D9SkC69SUts4bxrKXI0Y0Ry0/SEL2qxd/oNk8tlrbwhT7RPNE5 UMJXoKsHSbBm00Cz24Gm05ByxTm+Ewq6YdRpHaLbCWeeOLuyfhuCYww8qYl5BpIVOA5L VWLAayT4BUz3ovqXOs5dHQ22rUn/KI9wJ+vzABxiQRoAL7pGRd8eh5op8okafpHWV8a+ 4h2G5V2YKv5tgH5ekB9xZQL6DEfWoBqlZR2DhE8MvjrLaMGjAnnITw7wcwZHOOz6hG2i NZC5jYHiAD6eXGXSLuJKn/e/GBTcTZ6Ch26sifJzAciHUshCUg699FVjsiuc8L7Sny2h VKdg== X-Gm-Message-State: AEkoouvpJJn+MzntKo2U9U0qjQMY1FNdNOF8uKXuGgLHTrl+qYwIeqpiM3oUbsusxaEtosK//fBt/KVAy8zPsA== X-Received: by 10.28.28.70 with SMTP id c67mr12208311wmc.8.1471794171329; Sun, 21 Aug 2016 08:42:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.125.242 with HTTP; Sun, 21 Aug 2016 08:42:30 -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 17:42:30 +0200 Message-ID: To: Levi Morrison Cc: Aaron Piotrowski , internals , Stanislav Malyshev Content-Type: multipart/alternative; boundary=001a1144fb74c3c62a053a96c837 Subject: Re: [PHP-DEV] ReflectionType::__toString() prepending \ to class names From: ocramius@gmail.com (Marco Pivetta) --001a1144fb74c3c62a053a96c837 Content-Type: text/plain; charset=UTF-8 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. > --001a1144fb74c3c62a053a96c837--