Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103741 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 80684 invoked from network); 15 Jan 2019 14:21:45 -0000 Received: from unknown (HELO mail-it1-f169.google.com) (209.85.166.169) by pb1.pair.com with SMTP; 15 Jan 2019 14:21:45 -0000 Received: by mail-it1-f169.google.com with SMTP id c9so3808055itj.1 for ; Tue, 15 Jan 2019 02:57:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1pQyC7bePpASUrApgP1ptbLFvlNSUs7VmELJbwygX2E=; b=J0TwliVjTiynRV72R9cqrDuUf09R7kr10lruZZAgpCt8Rr9DUXMRX/JuNEDhi4n54r Jfpm9r9j/IqoZU9naTFxdCbFglYKoB/wigNhuoxuQYIjnUW2s0keQrww88UTUze99LBH MpD4v71PuaIXwMEbg7MdoPLLsgKU7/DE+saNWJ+ML1swMvCg/eapq5/R6Hy/L8TiUKLW YebhtCjS6/7VPjdwjGSOR61lcQpUgK2r6Qg9NyUM0Verpa8knwnwxSxttMFhop0tfGxu wZml8dwA+5z7H+DO7zZmnwLJz5fqRhqhC9hRpb43Z6cK9YYgixTfupn2kJwbozZvShkl qUiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1pQyC7bePpASUrApgP1ptbLFvlNSUs7VmELJbwygX2E=; b=KMwgPGYZ8SSvs3xzy8bxP+2MkGlAUIGB6O9CLBCbEf6pt2rupyvIxrDfVmtynbBjbb DPRZVsnOg7T6ELHpgI4HO7zto+6a/X5U0NODIdc6PeNFnXw/JMhPrpW/dbzBrUmig+du JuJUHveVf/QgJDpWb8WFWO6cKa3YhC3O3B4Zdb3wahaPsRXUqd7GBTSpbF+sLGtu0ep7 6TEx02uvWmjk+orIGhsnPWiFAwBmZyrU3ELQGiZrO0LM2i4Ezf+Vnf5yD/lzyizxbP1b oa1Qqx8WDinhvA3s4hc5DsjILeG8zWcVxJKxUggGyW2Vb2dv+acqVbLUqcADBwVMp+1D ihWA== X-Gm-Message-State: AJcUukcvKSQOs84klwv6RImNI5KOQWJXuuOMc/UvK2CjgNygj2n0FGHI 1M55xoV0UED3T/hek3DYOoZK7Q8RKyNcVRcBJOY= X-Google-Smtp-Source: ALg8bN45D/btIL9PMJarMK6a8WS3wy8EBNMjMRhOR2IhMHPSaVVPPJHNWFBj8UdiCea/q1p1xpSrFAigIX5xx1rUwa8= X-Received: by 2002:a05:660c:74b:: with SMTP id a11mr2069534itl.27.1547549856792; Tue, 15 Jan 2019 02:57:36 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 15 Jan 2019 11:57:20 +0100 Message-ID: To: Marco Pivetta Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000007c8688057f7d0721" Subject: Re: [PHP-DEV] [RFC] Reflection for references From: nikita.ppv@gmail.com (Nikita Popov) --0000000000007c8688057f7d0721 Content-Type: text/plain; charset="UTF-8" On Tue, Jan 15, 2019 at 11:30 AM Marco Pivetta wrote: > A few issues with the RFC so far: > > * `ReflectionReference` seems to be designed around arrays only: maybe > `ReflectionArrayKeyReference` or such? > ReflectionReference works with arbitrary references. Arrays only come in as a detail of construction. Constructors such as fromLocalVariable() or fromObjectProperty() could be added in the future under this design. > * Can the `getId()` return type be restricted to either `int` or > `string`? Why is it a union type right now? Technical limitation? > To allow changes in the future. The real return value here is an int, but the size increase due to hashing makes it a string. If we find a way to avoid that (or decided that we don't care about leaking addresses), we could change this to a (faster) int-based API. I'd be okay with renaming this to getHash() and restricting the return value to string. We could add getId() returning int in the future, same as we did for objects. > * `ReflectionReference#__construct()` should be `private`, since it is > unusable anyway > Done. > * `fromArrayElem` => `fromArrayElement` > Done. > * is this open for inheritance? If so, what scenarios would fit > inheriting from `ReflectionReference`? > Marked as final. > * what happens when `ReflectionReference::fromArrayElement()` is given > invalid data, such as non-existing keys? I'd expect it to throw. > It will throw, yes. Added to the RFC: > If $array is not an array or $key is not an integer or string, a TypeError is thrown. If $array[$key] does not exist, a ReflectionException is thrown. > * instead of `$ref1->getId() === $ref2->getId()`, `$ref1->matches($ref2)` > or such. > * what are possible scenarios for getting the identifier as a primitive, > and then storing it somewhere (like an array of reference identifiers)? > * There seems to be a lot of design around `ReflectionReference#getId()` > to avoid leaking internal pointer information: can it be completely > dropped, if we have `$ref1->matches($ref2)` instead? > As Nicolas already wrote, the ID / Hash functionality is needed to allow hashtable lookups. Having just matches() would require iterating over the whole set of known references and comparison each and every one. With the getId() API, it's just a single HT lookup. We could add $ref1->equals($ref2) as an *additional* convenience method, but it would not replace the getId() API. Thanks for the feedback! Nikita --0000000000007c8688057f7d0721--