Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130448 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 50CD81A00BC for ; Wed, 25 Mar 2026 11:53:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1774439623; bh=orDmBhSwomgPFVigZI/S3jBCWYCQ8IYMpBCvMYv1q0M=; h=References:In-Reply-To:From:Date:Subject:To:From; b=KeudDPjh7Pg34a/e9mO31Y3J5OP1iwSeS/GUv4KT/6UPUi0rQpREA8uz/dZYf1z9J 7U9LSuyujCwHTp1jp6DE+97tVZyQONXAoMeJndvslZY4arhU3ggDA5wGDoz6ZWqFxI EwM9zAzpYMbg+y3s7ZuuB2nb5qzSnOXj9rL1RuOX+jjsSAw9qkUH8JMIn1oHoTK6n/ YD0DEBHo+j6UwM1WIV+uJrvu62oOIHMltnbYG3O26DL4NnA6QZ0lcjFOfV2NHuSqWG dP376HEtBLNSVYQKoSnQwsbDb/pYEBnLHZBmebSa1lVdNMhGSLKsOIWGsltFvYDIOF lp8Y4M8gotqeA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2F29B1801E6 for ; Wed, 25 Mar 2026 11:53:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from developer-rob-server01.developer-rob.co.uk (mail.developer-rob.co.uk [35.176.203.165]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 25 Mar 2026 11:53:41 +0000 (UTC) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (Authenticated sender: contact@developer-rob.co.uk) by developer-rob-server01.developer-rob.co.uk (Postfix) with ESMTPSA id D17E2893B9 for ; Wed, 25 Mar 2026 11:53:35 +0000 (GMT) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-899e87b04d8so71408626d6.3 for ; Wed, 25 Mar 2026 04:53:35 -0700 (PDT) X-Gm-Message-State: AOJu0Yx9GyoHlJWC8aEv1ewxh+e1VA+wIuLAyAh+mfQeXQPxUv48jEU3 10dbQaky9e+mJUTF3yF3ETNDsUtoD0bNb6xWE1ff05sk6J3C0g7kRGFht0zEPvTh/Gunuyxjs4o BNLjSgEZtc/jwMIaCFFPx1cl7ZGE7oOw= X-Received: by 2002:a05:6214:110f:b0:89c:8681:36fa with SMTP id 6a1803df08f44-89cc4adc5e5mr35957746d6.32.1774439614845; Wed, 25 Mar 2026 04:53:34 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 25 Mar 2026 11:53:23 +0000 X-Gmail-Original-Message-ID: X-Gm-Features: AaiRm53bp-JdDIp2xfcEd4VtabuMYd4GqAv_WmDzeIVhH1MtjMjf-1eEVfV0v00 Message-ID: Subject: Re: [PHP-DEV] [IDEA for RFC] class_uses and optionally returning traits for parent classes To: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" From: contact@developer-rob.co.uk (Robert Humphries) >> it isn't documented why it only returns traits on the current class > The reason is given here: https://bugs.php.net/bug.php?id=61554#1333085728 : >> Traits are outside the inheritance system: the >> parent class is effectively defined by the composition of its own >> methods/properties and any traits it uses, so trait usage is not actually >> inherited. Furthermore, it doesn't really make sense to reflect trait usage down >> the class hierarchy because the same trait may be used more than once within a >> class hierarchy. Thanks Claude, that is useful to note, when I initially looked, I was looking for `class_uses` in particular as opposed to `getTraits` from `Reflection`. I am not sure I agree with the reasoning though. If you are using `class_uses` in the first place to check for a trait's presence, then I can't find any difference in use cases for if a trait is defined at the current level or parent level. Although the trait is not inherited, the _effect_ of the trait is. (While you might get differences in behaviour if using multiple traits and specifying `insteadof` to resolve conflicts, what functions from the trait that were used/not used are not provided by `class_uses`, so the same trait being used more than once doesn't affect any changes to the function other than needing to dedupe the list) ~ Robert