Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110494 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 9741 invoked from network); 12 Jun 2020 06:17:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Jun 2020 06:17:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 20C151804CB for ; Thu, 11 Jun 2020 22:01:34 -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-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (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 ; Thu, 11 Jun 2020 22:01:33 -0700 (PDT) Received: by mail-io1-f45.google.com with SMTP id r2so8963241ioo.4 for ; Thu, 11 Jun 2020 22:01:33 -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=b6K1tYWylRBKmkfb52ZvzV/Gg2s2WjtyZkvzbshXHps=; b=BtqkilWcHh5sx3taqzM/ihwa+/rfZ8AmpK3jr+nim2uWc2NEF1Yqkrpjl8xOegl20H PLtL5gHMqz502MuIwwN3pFX4MtPg7ZwSScSRwrUUe9pJwqFz7GXbwdXTWx0S8vlvzckB KUQuwWml3e0/V+6SBSJZGBlrNkKowHAmm99qqqMeIqpFI556UlgL8NYj3sPj+Wx6AJYD pxiQ34rzx8tqGEHToK44FywnGcpeDSWWxn0v4BvzmvCJRS1dWr0m4YhirNSn4n/IYNPy l0/mPgejgLdwqkyEftGXxbp/YnGhdqvTyegoAPeNJ1ZlX+Dj2B/dIJCmAGLWsDNSa527 KvWA== 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=b6K1tYWylRBKmkfb52ZvzV/Gg2s2WjtyZkvzbshXHps=; b=SIxQ3fWjvdX7ZT3FPLO0YfmrdO2eynU79h5uE1ipyr8pN2SlQWUwwm8eDqZsqQWy2i dHeZ4omUFGsUZCiIw0bGOjALS7D06I9tzq/TGxyZ5txSR0WjJXF1lEIcoQsuZSGdarE0 rZf8fquxjSTbF7r4QZqtrosbzgc3X0cRsv67oyDcIC3p5r2JHYNoAJMsaOhEtdBUbLNU QqYcZVPQ035IriYM1dDiilZVNQNgZB07jWftTOpDlnQfKiCFhPECZ6T3gt4/zAYQHOCw JkdMSfN2wI91E9WIciTJ5pIVy4Zeqm98vwTImMxb4N4+s5uQ0zRMENabeA0LjYp1Pwub h/Dg== X-Gm-Message-State: AOAM532Bq1+xSS/m0x0GgFSYEcfNiliC+qv+UsKpgxjLRu6nS0CvLoPF HnKlpWJKRoLtXLHZi8QhMzWVZiDfNOlq85EeNiSsdqjx3Fw= X-Google-Smtp-Source: ABdhPJwqk1X848rf5n3QiFdRiCkxoslbIcq/fxFJOS/8zDXC/KzBnNb2L4y+xAX3Lz8LsoWII7ux1S5XrkRREyNzZQw= X-Received: by 2002:a6b:5f06:: with SMTP id t6mr11500002iob.88.1591938091615; Thu, 11 Jun 2020 22:01:31 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 12 Jun 2020 00:01:20 -0500 Message-ID: To: Nikita Popov Cc: 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) Aaand I sent that too hastily...Specifically for question 2 around `ReflectionConstant`, I just noticed `ReflectionClass::getReflectionConstants()` exists...Scratch that question! Sorry! On Thu, Jun 11, 2020 at 11:31 PM Troy McCabe wrote: > > Hey Nikita, > > Thanks for the thoughts. > > > Could you please explain in more detail *why* we should duplicate exist= ing 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 hist= orical artifact, because they were introduced before Reflection was a thing= . Unless there is a strong reason to the contrary, I would prefer reflectio= n 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 obvio= us 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