Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130449 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 0F0D81A00BC for ; Wed, 25 Mar 2026 12:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1774442963; bh=hyUOG41MDxWBw53Y4uZ3V+BKGnyeiW15YPnCbAAtxsk=; h=Date:To:From:Cc:Subject:In-Reply-To:References:From; b=jMmiFsVpH80wbEzRN0HBiqF0kfqXnYwjAhXVHlZAjT2Zhe2j7Ep4Fctp05u5JBRZ2 nBxCMPHkM9HC95QzrgzK96u44O7kfTDPPhc37Q/3tY0fRfHErII+HE86pu2LY8NsrM nPyutCbL6spRrjDip1siT5B418FYv27chV56dcNcM2e7iaTZPe0R8egKnTQ8oREW0o SoXu5khng9+TgWBhhZuPICKlseOw88fD6VTsQG417GpA9Lr8m3kyYIxH1odqvlUYJW PlyldGYKW6tF9MghcQsrs2kMp8LCB/xRJKeypwIp7sR5YOlZOibpebynCFoJuyIvh4 ApEx2OkodWs+A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BB588180083 for ; Wed, 25 Mar 2026 12:49:21 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-4317.protonmail.ch (mail-4317.protonmail.ch [185.70.43.17]) (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 12:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gpb.moe; s=protonmail2; t=1774442952; x=1774702152; bh=hyUOG41MDxWBw53Y4uZ3V+BKGnyeiW15YPnCbAAtxsk=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=f6Kl8ZrgOeGL5I6Uy4rZ1QTUv6zyZxT6KSOrJnWK0qTyhaaInk0c5ydCVRmvxxLpA F6lozsOZEnv0pqJRxdt2880hbqzfex/SR44RoZP7yfHlQ22jBAj4ul7SiwZDPqgfXo 5c1UxX37lFm0UwNLaDKluIgdNSABWHbZ6P/IpHqLfUKrpjXAjp5vbuxFvDvz9c7/Q8 SXgnEYPPHA448R6urrZXH5aDtW6zUnDuHt6BtLS8gjceQBgv+3sLN6n4d+67Zf8qZ6 lzcEZ7OK+Qsg2UzsIVoPVRGs5X9k8alKuiAVoTgBjsdzC5yxWOIWz5g1p9TYx6Ixcs yWzSf2YX6UEpA== Date: Wed, 25 Mar 2026 12:49:08 +0000 To: Robert Humphries Cc: internals@lists.php.net Subject: Re: [PHP-DEV] [IDEA for RFC] class_uses and optionally returning traits for parent classes Message-ID: In-Reply-To: References: Feedback-ID: 96993444:user:proton X-Pm-Message-ID: d8f7b67aaeb5749cf4bff98fa8c6d01ba9fa3b22 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: internals@gpb.moe ("Gina P. Banyard") On Wednesday, 25 March 2026 at 07:40, Robert Humphries wrote: > Good Morning Internals, >=20 > I am aware that traits in general are a topic where people can have > strong opinions, so I wanted to get an idea of initial thoughts on > this before deciding if it is worth looking into any further. >=20 > At the moment, there are three functions in SPL that allow access to > what a given class is using in some way: > * `class_implements` > * `class_parents` > * `class_uses` (returns the traits the current class uses) >=20 > `class_uses` is unique out of the three in that it only returns traits > declared on the current class as opposed to the parent class (and > higher in inheritance). While this is documented in the manual, > looking at the original bug ticket that introduced `class_uses` > (https://bugs.php.net/bug.php?id=3D55266) then it isn't documented why > it only returns traits on the current class. As far as I can tell from > the bug ticket and the code, `class_implements` was copied for > `class_uses` and while `_zend_class_entry->interaces` contains all > interfaces (including from the parent classes), > `_zend_class_entry->interaces->trait_names` does not. >=20 > So, in terms of my question; what would be the general thoughts on a > new optional argument to `class_uses` that iterates to each parent > class, adding the traits from the parent as well? Frankly I don't like the existence of these 3 functions in SPL. This is very much in Reflection territory, and it should only ever be in Re= flection. SPL is already a mess of badly designed "features" trying to cohabitate. The Reflection extension is designed to give you access to do introspection= with a well-defined API. But more over I don't even think you addition makes that much sense. Traits are not part of the inheritance hierarchy, that's because the "compo= sition" of traits is effectively just copy and paste. Interfaces are fully inherited onto any child class, so there is no need to= iterate through the parents to gather all interfaces. Traits do not work this way, any "prior" use information is not transmitted= due to the copy and paste nature of them. The current API doesn't even tell you if used traits also use other traits. I don't even know how it handles trait aliases, or if it even cares about t= hem. And that's not even going through overridden trait methods/props/constants = at any stage of the inheritance chain. So I'm very much not convinced about this, nor do I see really the utility = of wanting this information? But anyway here is a small snippet that will fetch all used traits: https:/= /3v4l.org/kvQGR Best regards, Gina P. Banyard