Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120448 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 96741 invoked from network); 30 May 2023 02:43:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 May 2023 02:43:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 35B7A180546 for ; Mon, 29 May 2023 19:43:07 -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-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 ; Mon, 29 May 2023 19:43:06 -0700 (PDT) Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-bad041bf313so5761920276.0 for ; Mon, 29 May 2023 19:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20221208.gappssmtp.com; s=20221208; t=1685414586; x=1688006586; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=6HHr+4RlBrr+HUE//ESdf4rKsUE+psxqQUVUv3NXe/U=; b=Fnu1QOePwAmKGevXRPSzjfWBVlERgemKphaGvimdlLfzpSD3HbI0FarcoIoVtsW9+Q RXg6JzffJyRF5RQkZTBvnFuMe7OK2lnkYfZpRhGdWIW8sSub1T885dADW+BcmiRs9Pci ylWrGiQS2LIubqGRNndw3QhMR4thFHPjrT/QQW9X8r1UvscgEfEwJ8lUWt+R/yjP277X BfrxCnIEdfyWgpt49ZnAe+xLShWvVZGDizgM+imIGUvYSXvhceAZV2cYYcSF7ZU+Y/8P u44pfiuL24CcGmPM/J7/++7RL6SbI8x+nlfLkyPTaIkfoLe3wWgNjnpk3P79j303Xd5e dpaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685414586; x=1688006586; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=6HHr+4RlBrr+HUE//ESdf4rKsUE+psxqQUVUv3NXe/U=; b=AzfZC1qywqg5yUoSJ5LT0lW6SRCojM0pMBCJG+bE9Aj+kQpVEcaEq1OMhuG6iSNuqp AbS21LWgHqoX+QrEHUVZAxByxAaWdMujfq480OImHKNn3Xj5kcsVT6j/FS/+GeRzmdQ8 P4wmQQTCscz+72B4gDW+j7Z8gda380KOvcMUWfS4JVMXbntyp8/tgPXLM07XDo2Klvxd mOSaFkU3YB8t7ydu3KZyKSw8zn7wo/iJIawlR/FpNghryZHWPcBfQVthqLKjJu5oIORJ ypw1ZW0xC9UlerX847rnssaaFANZ1nq9ls8y2SgXlZP0WqiHe6fl9HMadzT6WrkBqMtF zuhg== X-Gm-Message-State: AC+VfDyP7NhSgeFHMF/JvEE/sk1vBPZJbg7Ubkyzg7xGFmA3iBiQWLsO VtGWBwmhN3cyulU17IfZ/JhRazrtFLx/TybLGsVKJkAPcz02qHIfJz4= X-Google-Smtp-Source: ACHHUZ4iytUoYjxttNGSMMg05HM3wjdT2ahn6vhzEe9+9SLQZNKHLzHS24j0POMJIIZ9Qe47tyCKPSi0OljowD9uI+0= X-Received: by 2002:a25:311:0:b0:ba1:66fa:ad35 with SMTP id 17-20020a250311000000b00ba166faad35mr1110888ybd.53.1685414586139; Mon, 29 May 2023 19:43:06 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 30 May 2023 04:42:55 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Let ReflectionMethod keep track of original class From: andreas@dqxtech.net (Andreas Hennings) 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. --- Andreas