Bug #67577 [Opn->Ver]: Unintuitive __CLASS__ magic const behaviour when in a closure from a trait.

From: Date: Wed, 17 Nov 2021 17:27:30 +0000
Subject: Bug #67577 [Opn->Ver]: Unintuitive __CLASS__ magic const behaviour when in a closure from a trait.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237826@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67577&edit=1 ID: 67577 Updated by: cmb@php.net Reported by: elliot at aanet dot com dot au Summary: Unintuitive __CLASS__ magic const behaviour when in a closure from a trait. -Status: Open +Status: Verified Type: Bug Package: Scripting Engine problem PHP Version: 5.6.0RC2 Block user comment: N Private report: N New Comment: Yes, that doesn't look right: <https://3v4l.org/qn3nQ>. Previous Comments: ------------------------------------------------------------------------ [2014-07-06 02:59:08] elliot at aanet dot com dot au Description: ------------ The __CLASS__ magic constant behaves very differently for closures defined in a trait. It seems to use the bound scope class for the closure rather than the class which it was actually used in. You can see the current behaviour here: http://3v4l.org/WIK1E#v540 This can get even more unintuitive when using normal methods and reflection to get them as a closure seen here: http://3v4l.org/EhVlW#v540 Considering traits are are essentially copy and pasted into the used class, would it not be more correct to use the class in which it was used in instead? Expected result: ---------------- Before bind: __CLASS__ in class: string(17) "ClassConstantTest" __CLASS__ in Trait: string(17) "ClassConstantTest" After bind: __CLASS__ in class: string(17) "ClassConstantTest" __CLASS__ in Trait: string(17) "ClassConstantTest" Actual result: -------------- Before bind: __CLASS__ in class: string(17) "ClassConstantTest" __CLASS__ in Trait: string(17) "ClassConstantTest" After bind: __CLASS__ in class: string(17) "ClassConstantTest" __CLASS__ in Trait: string(8) "stdClass" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67577&edit=1

« previous php.bugs (#237826) next »