php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68931 Class with Trait is not contained in get_declared_classes()
Submitted: 2015-01-28 10:57 UTC Modified: 2015-01-28 20:18 UTC
From: bastian dot schneider at commerce-plus dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.6.5 OS: Windows 7 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bastian dot schneider at commerce-plus dot com
New email:
PHP Version: OS:

 

 [2015-01-28 10:57 UTC] bastian dot schneider at commerce-plus dot com
Description:
------------
Problem
- "TestClass" is not contained in get_declared_classes()

Circumstances
- the class uses a Trait
- get_declared_classes() is called before the declaration of the class

Test script:
---------------
trait CAS {}

// with use CAS = 135 classes
// without use CAS = 136 classes
var_dump(sizeof(get_declared_classes()));

class TestClass
{
    use CAS;
}

Expected result:
----------------
I would always expect 136 classes 

Actual result:
--------------
135 classes, TestClass is not contained

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-28 16:01 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-01-28 16:01 UTC] nikic@php.net
You check get_declared_classes() before the class is defined ... Classes using traits are not early-bound.
 [2015-01-28 16:40 UTC] bastian dot schneider at commerce-plus dot com
Yes, so it is. But in this case, the behavior is not documented. 

If I check get_declared_classes() before a class with trait, the result is different from a class without trait. If it's a feature and not a bug, it should be documented in http://php.net/manual/en/language.oop5.traits.php or http://php.net/manual/en/function.get-declared-classes.php, don't you think?

Thx and keep up the good work!
 [2015-01-28 20:18 UTC] requinix@php.net
@bastian: see also my comment on bug #68936, which was coincidentally (?) created minutes before nikic replied here.

It seems to me that it's not that classes using traits are not documented to not be early-bound, which is too many negatives for one sentence I know, but that classes using traits do not benefit from the undocumented early-binding "feature" that typical classes do.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 16:01:27 2025 UTC