php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67577 Unintuitive __CLASS__ magic const behaviour when in a closure from a trait.
Submitted: 2014-07-06 02:59 UTC Modified: -
From: elliot at aanet dot com dot au Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 5.6.0RC2 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-07-06 02:59 UTC] 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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun May 26 21:01:26 2019 UTC