Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:101308 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 25251 invoked from network); 11 Dec 2017 07:59:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Dec 2017 07:59:00 -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 209.85.128.169 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.128.169 mail-wr0-f169.google.com Received: from [209.85.128.169] ([209.85.128.169:42114] helo=mail-wr0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/D7-53433-1CA3E2A5 for ; Mon, 11 Dec 2017 02:58:58 -0500 Received: by mail-wr0-f169.google.com with SMTP id s66so16503021wrc.9 for ; Sun, 10 Dec 2017 23:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=8vPOMS9GBFog+kRgVUHfDsU/Tqdcp2VqjophyVZ4Gbw=; b=myj35vRID3h6ZsEo5weA5crsIuJTF8LMy51um7Sv2G4Bej2aXZ1UgXoCjZBE3V2pz7 5ZeXZxbrZC4P0Ttih3R5yS/E0QGayUgkyeiD4IJXwpOlcgNZXhl/me47Xgb7Wo+jT/2e 4tWNLjWTvEoF1Fd2R/xCPH5yi1frZwS82sRNXGDnxjOSqons7lVsojkm4Gu0XTpe2DQw kULn68e/K8dFIP110SfkBtOqhJnByKmStKt9hkVIAPyUKTM2JZOIVnvrni+DkM1SS5G9 0QxP8GHxC33Y9K4KTyRxPhbjEO8C55SRs/i6xQWWxBnTffSY7O9tCBV4885AShd3+3IN U4cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=8vPOMS9GBFog+kRgVUHfDsU/Tqdcp2VqjophyVZ4Gbw=; b=o42pu4YDiWsNvbswkS93VqF2rt/+HmLDA040wHoIhLp+G3doxIznHlP0kLKtALPbtJ z5LmxyXLU3XvGeKZLcqpP/MAxLwwwJFeBYJMJhkto73hAfujVUAQSAABQ+j1Pf2PDkjq 7ssxga5KRRIUoaZVLPuq/zZCzgO5u5I7Ct3L+1KEuU0QtkrHq0LwBrNZPnljrMhiJKwv qY96Hk8yDIRHrDwxwNq4WlxIO4yk7Ff6yclmaCWgyuCtsAImPt9pqMWpTmjLuHpjXrzO cY7InVA4iar/V4pFAQm6EnF0ImYC1ibp39QKyd94IUyeN81qb/l34uHvbO6Jos/ZoRFA QHFQ== X-Gm-Message-State: AJaThX4lCQMN8V0VLSDIrNs7y8Pj5ctE02OyBZBCdJDXzLfc0CtcCvEO aG92Y+LZMTL6sTCV0eAA0vReL+P9Vw6J8hZ+3d4= X-Google-Smtp-Source: AGs4zMZgZtGNnLQnbLxqTUn1eJdu4tNxdOufB7GV+zeQyxzFFOop4YZIt14Iw4PHvPytLNe9pI1ntixBcqvcE7HzwY0= X-Received: by 10.223.131.70 with SMTP id 64mr31676783wrd.114.1512979134413; Sun, 10 Dec 2017 23:58:54 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.184.205 with HTTP; Sun, 10 Dec 2017 23:58:53 -0800 (PST) Received: by 10.223.184.205 with HTTP; Sun, 10 Dec 2017 23:58:53 -0800 (PST) In-Reply-To: References: Date: Mon, 11 Dec 2017 08:58:53 +0100 Message-ID: To: Andreas Hennings Cc: PHP Internals List Content-Type: multipart/alternative; boundary="94eb2c0d2476dc002805600be7fd" Subject: Re: [PHP-DEV] Reflection API: Add static factories on ReflectionType From: ocramius@gmail.com (Marco Pivetta) --94eb2c0d2476dc002805600be7fd Content-Type: text/plain; charset="UTF-8" What's the use-case for creating a userland `ReflectionType` instance, besides mocking the reflection API itself? Consider that the subclassing in userland already provides an easy way to perform these operations (although ugly): https://github.com/Roave/BetterReflection/blob/2.0.1/src/Reflection/Adapter/ReflectionType.php Not trying to drag down your proposal, but as you can see this is already being done and works very well and is very well tested for BC compliance (should new methods land into `ReflectionType`). Also, I'd add that a the proposed API should accept `InternalType|ReflectionClass|null`, and not `string` (separate named constructors would be best) which is basically the reason for most hair-pulling around the PHP lang. A small `InternalType` VO that throws on `InternalType::fromString() : self` would be extremely beneficial to avoid the continuously growing list of edge cases and additions required to accommodate for new internal types being added to the language. On 11 Dec 2017 08:25, "Andreas Hennings" wrote: Currently there is no (documented) way to directly create a \ReflectionType object. The class has no documented constructor. I propose that static factory methods shall be added for this purpose. This will be useful for code that wants to dynamically create and pass around reflection type objects. /** @var bool $allowsNull */ $t1 = \ReflectionType::fromBuiltinType('string', $allowsNull); $t2 = \ReflectionType::fromClassName(\stdClass::class, $allowsNull); assert(true === $t1->isBuiltin()); assert(false === $t2->isBuiltin()); assert('string' === $t1->getName()); assert(\stdClass::class === $t2->getName()); To be discussed: - method names - Whether to return ReflectionNamedType or ReflectionType or something else. (I don't find ReflectionNamedType documented in http://php.net/manual-lookup.php?pattern=ReflectionNamedType) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php --94eb2c0d2476dc002805600be7fd--