Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120469 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68450 invoked from network); 30 May 2023 16:54:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 May 2023 16:54:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 97F971804D7 for ; Tue, 30 May 2023 09:54:42 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 30 May 2023 09:54:42 -0700 (PDT) Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-bad05c6b389so6583289276.2 for ; Tue, 30 May 2023 09:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20221208.gappssmtp.com; s=20221208; t=1685465681; x=1688057681; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=E6KLpptr097PY7XwemtJbkiZlhLe3CMDU2EYLi7RyIY=; b=zM7VbsLgMSHu/eqRqGo9syqJPLIQAhqii6Il4in2WmEjC7eW4J6aMTNhIm7FSgmAtc jbroPDBNGsftPMnwvR1JqnOl+OtRXJ2wlNZL/beLrPquuQudO6jIYdFVp3lkNPmKZ9uo NwDH25qA9Sq/0p/5jSJWR5nD6IHTWj0m4PsCjGE8XJuFOPaxCp+moqQz2rWgXTY0KC2w 2xMrBNmdLqxTQItVE5gwtVD4JJ3fWZgohQ3luoVjGYp0xPJEz8Tpgwc0rrCbVNXSLs4e 7zjqoY77Ao0aWGAGlEbVLACE06RMgmVvhSn4lmGJsteuycVJM80nUeugrHJu1zDsvOVu 5u9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685465681; x=1688057681; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E6KLpptr097PY7XwemtJbkiZlhLe3CMDU2EYLi7RyIY=; b=TO/xcBcbITxaun+yl2KDrXx0MQXx12LZMlDOS1Eli6ExM9Vsmu4ZhRJmJuklqFVou+ zXahE/KwI1NJQEUzuOqj5Gxe8Gk5zxSLh4XR7dXaB28rNQ91P3CvrSl5xDbx/6At8IrW w9H1xjAIv4Jy3MoDYzBICeO+S9Q9KFaNHo1/gWzZQNWXplKtGxA7UNFvBrNC6Zj3sqvV 79yTaQMnYTFWoML3Vu3QlQePt4nkw/u/E2FKWPeFVLFt4eHKC2sE0h5btIX9rK1/UYOV sVTe0lkVc8M3+z+7OSEeMV3PLuoMxhpZDuNMMFV3GN14g8JyXYBDvbOjOKaTpDuxK/W3 pZ0Q== X-Gm-Message-State: AC+VfDwLUlKquxbCOf+SsrHjBLJW4tC1xDhnmyqze7RNqeUs40PdxZ8Y P1FyksfJgi7UY+Lm14qUKZWF8brVQnvQOC4YfouP9e9aJ6hG4PQPQRAHeg== X-Google-Smtp-Source: ACHHUZ5HI127VjCW3dWxxHr3zz6Xybcv2pvQz3NQwKwGnVLSXKJGnmG4CBd8W4oOK1jx5UsCNI5iGoMkmL0UH2IJjKA= X-Received: by 2002:a25:aa03:0:b0:ba1:d664:caed with SMTP id s3-20020a25aa03000000b00ba1d664caedmr3768985ybi.36.1685465681588; Tue, 30 May 2023 09:54:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 30 May 2023 18:54:30 +0200 Message-ID: To: Larry Garfield Cc: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Let ReflectionMethod keep track of original class From: andreas@dqxtech.net (Andreas Hennings) On Tue, 30 May 2023 at 18:48, Larry Garfield wrote: > > > > -- > Larry Garfield > larry@garfieldtech.com > > On Tue, May 30, 2023, at 2:42 AM, Andreas Hennings wrote: > > Hello list, > > this proposal will be useful in combination with "Declaration-aware attributes" > > > > > > Problem > > ======== > > Currently, ReflectionMethod is not aware of the original class, if the > > method is declared in a parent class. > > Methods that are called during a discovery algorithm that need to > > process a method with its original class typically need two > > parameters: > > > > function processMethod(\ReflectionClass $class, \ReflectionMethod $method) {..} > > > > > > Proposal > > ======== > > Let a ReflectionMethod object keep track of the original class. > > Introduce a new method ReflectionMethod->getOriginalClass() to retrieve it. > > > > class B { > > function f($x) {} > > } > > class C extends B {} > > > > foreach ([ > > // There are different ways to get a reflection method object, all > > of them track the original class. > > new ReflectionMethod('C', 'f'), > > (new ReflectionClass('C'))->getMethod('f'), > > (new ReflectionMethod('C', 'f'))->getParameters()[0]->getDeclaringFunction(), > > ] as $rm) { > > // The following won't change: > > assert($rm->class === 'B'); > > assert($rm->getDeclaringClass()->getName() === 'B'); > > // New method: > > assert($rm->getOriginalClass()->getName() === 'C'); > > > > > > Alternatives > > ========== > > > > At first I thought we might introduce a new class like > > "VirtualReflectionMethod" which behaves as if the method was declared > > on the child class. But this is awkward. > > > > I think the ->getOriginalClass() is much simpler. > > > I would not be opposed to this. I don't know that I have any use cases for it, but I'd be open to it. You can search in your favourite project's /vendor/ directory for methods with two or more parameters that receive reflector objects. "function .*\(.*Reflection\w+ \$\w+, .?Reflection\w+ \$\w+" > > --Larry Garfield > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php >