Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110507 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74502 invoked from network); 14 Jun 2020 14:03:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Jun 2020 14:03:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 03F191804CE for ; Sun, 14 Jun 2020 05:48:27 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f170.google.com (mail-il1-f170.google.com [209.85.166.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 14 Jun 2020 05:48:26 -0700 (PDT) Received: by mail-il1-f170.google.com with SMTP id i1so12772029ils.11 for ; Sun, 14 Jun 2020 05:48:26 -0700 (PDT) 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:content-transfer-encoding; bh=+zVKDqrlgRJPZARt1sT6SqM49as2+QzTaXx3IMy8PEQ=; b=IHBaawRO1sDp66+RpQisXBy5Y4fFuGle4iTiNqFay6dNFA1/qghu9nF0Jb0yJ4cSkD mPE1SLcNQaN618lWLeWz1lH1WgmpgU+0JeSOfs789/AC34VWyElVXGBsL14wP5IoNroj SdM8xgIig5eJ7+badnSogoaD4aL677NQjF7oUu28EvsXOQsXuEy81u/Ps9Hno1wBz2r6 KxsgUFsWUh5n3lay7VQ7Z5DJgELeq/GmO/RllqRNuNZ0NNUCq/qg13R/N+BO+lJOu38r 1HahpFTAoMf8+PT5r9oZ0me4nAAJCIMLUlqWMHpsJSZdtpOuD6peOjOD5G0rbTt2Bg92 8BTg== 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:content-transfer-encoding; bh=+zVKDqrlgRJPZARt1sT6SqM49as2+QzTaXx3IMy8PEQ=; b=HQbMdJflehuwsYfOAx87LGzrYU9ouyFlGLEnRDb2Wa2YL/D6XviDDRAYrBu9hPxvaF cfGVFZ4yTy43h6SVAch/i7z2RcwH9/tBzz9/moOyeZOOiyGAjNNS/yTwkllXpyutjNbe jsBW6ETtyWe3cxaGvd8VXzSS6T5rgYvPGyIMK3US38W3AEbU5WNtTjRjBcXu2lDVzqGI BAz0AZMRrMkLf6AooICBKQ8oqxUg5b3dHjCgwwyOGJjBxOrRLQXGAPi7uC7xZ1k013Hd bbJqpOKU80yrFY+7QN/oriBa/FPfcVmpV01aS0kMGV8KHau8NBwI2pDpamyrsy1Y+ipZ EJYA== X-Gm-Message-State: AOAM530olr0CCZnxsoZYI4uEoCJ/qOq+58xVMkAu6UiNbeWQcrp3QGoR 5gw1MovFiOsUiOtZoXaV2gQ4/zBwJwswb5XH/iA= X-Google-Smtp-Source: ABdhPJwiB4fcV9IBjDbo4dYMHQsbcu3/njjhsP98aex8oU215rAfVpFPN2tV3FPQK41mJ3XTGFtv0HyxwYGoq9gIdP8= X-Received: by 2002:a92:c048:: with SMTP id o8mr21927936ilf.202.1592138903606; Sun, 14 Jun 2020 05:48:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sun, 14 Jun 2020 07:48:12 -0500 Message-ID: To: Chuck Adams Cc: Nikita Popov , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Revisiting proposal for addition of `get_class_constants()` From: troy.mccabe@gmail.com (Troy McCabe) I really appreciate the thoughts & discussion--I'll put this to bed. Thank you for talking through it with me! On Fri, Jun 12, 2020 at 10:11 AM Chuck Adams wrote: > > > 1. It aligns with the addition of the functions referenced in the > original post (`str_[contains|starts_with|ends_with]()`), and one > their stated reasons of simplifying the API for userland developers. > > Two reactions to this: One, reflection isn't a facility for novices, > so there's no need to cater to it. If novices end up needing such a > method frequently, something else is wrong other than how accessible > that method is. > > Two, reflection being all about reflecting over objects and classes, > it seems reasonable to limit it to an OO API. Any existing global > functions in that arena should just be considered legacy. > ReflectionClass is not final, and I can see plenty of use cases for > subclassing it. > > On Thu, Jun 11, 2020 at 10:32 PM Troy McCabe wrot= e: > > > > Hey Nikita, > > > > Thanks for the thoughts. > > > > > Could you please explain in more detail *why* we should duplicate exi= sting reflection functionality into free-standing functions? > > > > In terms of the *why*, there were three main reasons: > > 1. It aligns with the addition of the functions referenced in the > > original post (`str_[contains|starts_with|ends_with]()`), and one > > their stated reasons of simplifying the API for userland developers. > > While `(new \ReflectionClass(MyClass::class))->getConstants()` isn't > > the most difficult thing to grasp, it's not immediately clear to new > > developers, and is more verbose than > > `get_class_constants(MyClass::class)` > > 2. `get_class_[methods|vars]()` existing as built-in functions, > > creates a gap to retrieving class constants in the same way. If I > > start down the path of class inspection using `get_class_*()`, but > > find I can't retrieve constants in the same way, this is an > > inconsistency. > > 3. When using Reflection, accessibility is not respected as it is with > > the `get_class` family of functions. In the event that a developer is > > looking for constants which are accessible to the current context, > > there's no way (that I'm seeing, anyway) to retrieve _only_ constants > > accessible in the current context. > > > > > I believe the existence of functions like get_class_methods() is a hi= storical artifact, because they were introduced before Reflection was a thi= ng. Unless there is a strong reason to the contrary, I would prefer reflect= ion functionality to stay inside Reflection... > > > > This is good background that I wasn't aware of (I knew the Reflection > > API was newer than the built-in functions, but not that the > > `get_class_*` functions were generally frowned upon). > > > > It does bring up 2 questions: > > 1. Obviously this is a much larger discussion, but is there any > > appetite to deprecate & remove the existing functions in favor of the > > Reflection API? > > 2. An alternative to adding `get_class_constants()` would be to > > introduce `ReflectionConstant` as a return type from > > `ReflectionClass::getConstants` to match `ReflectionMethod` & > > `ReflectionProperty`, which would solve point 3 above. Would this be a > > preferable approach? > > > > > You do mention performance as a benefit, but it's not immediately obv= ious to me which use-cases are bottlenecked by class constant reflection. > > > > Enum implementations are the big case for this. While the libs I've > > looked at use an internal cache, these caches are per-request, so > > reflection will need to be used as many times as there are enums in a > > given system. Depending on the scale, this could be an appreciable > > amount. Obviously external caches could be leveraged, but that then > > requires additional development lift, instead of using battle-tested > > enum libs. > > > > Thanks for the thoughts, and thank you for all your work on internals! > > Thanks! > > Troy McCabe > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > >