Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95342 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86144 invoked from network); 21 Aug 2016 14:38:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2016 14:38:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=aaron@trowski.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=aaron@trowski.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain trowski.com designates 199.38.81.6 as permitted sender) X-PHP-List-Original-Sender: aaron@trowski.com X-Host-Fingerprint: 199.38.81.6 mercury.negativeion.net Received: from [199.38.81.6] ([199.38.81.6:65166] helo=mercury.negativeion.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/82-50790-ECCB9B75 for ; Sun, 21 Aug 2016 10:38:07 -0400 Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 046753EBC970; Sun, 21 Aug 2016 10:38:04 -0400 (EDT) X-Virus-Scanned: amavisd-new at negativeion.net Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2ZwXzQweMByb; Sun, 21 Aug 2016 10:38:03 -0400 (EDT) Received: from [10.0.1.3] (unknown [173.225.150.231]) by mercury.negativeion.net (Postfix) with ESMTPSA id 4FBF63EBC95A; Sun, 21 Aug 2016 10:38:03 -0400 (EDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) In-Reply-To: Date: Sun, 21 Aug 2016 09:37:56 -0500 Cc: internals , Stanislav Malyshev Content-Transfer-Encoding: quoted-printable Message-ID: References: <0668D584-EE51-4932-85D7-01D8BF70E409@trowski.com> <15E198DD-FF66-475D-ABBC-54ECD2B6BF62@trowski.com> To: Marco Pivetta X-Mailer: Apple Mail (2.3124) Subject: Re: [PHP-DEV] ReflectionType::__toString() prepending \ to class names From: aaron@trowski.com (Aaron Piotrowski) Hi Marco, > On Aug 19, 2016, at 1:31 PM, Marco Pivetta wrote: >=20 > Hi Aaron et all, >=20 > I tried to implement support for 7.1 in zend-code as a start: >=20 > https://github.com/zendframework/zend-code/pull/87 >=20 > A few issues arise: >=20 > * `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) >=20 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: >=20 > ./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