|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67114 sometimes class_exists() does not works on a class using traits ...
Submitted: 2014-04-23 09:57 UTC Modified: 2014-04-23 18:25 UTC
From: php at sunyanzi dot me Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.11 OS: debian wheezy
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: php at sunyanzi dot me
New email:
PHP Version: OS:


 [2014-04-23 09:57 UTC] php at sunyanzi dot me
function class_exists returns wrong result when a class used traits ...

in clear way ... just see code below ...

Test script:
var_dump( class_exists( 'baz' ) ); // true 
var_dump( class_exists( 'bar' ) ); // false

trait foo { }

class bar {
    use foo;

class baz {


var_dump( class_exists( 'bar' ) ); // true

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-23 18:25 UTC]
-Status: Open +Status: Not a bug
 [2014-04-23 18:25 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is a nifty case: Only "simple" classes are fully available after compile time, classes with "complexer" things (interface,traits, ...) will be bound and made available at runtime in the place where they are declared, else constructs like

  include 'someinterface.php';
  class C implements someinterfae {}

won't work. same with traits.
 [2014-04-24 01:54 UTC] php at sunyanzi dot me
my mistake ... thank you for your comment ... i am appreciate for that ...
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Feb 07 15:04:12 2023 UTC