php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
8 + 49 = ?
Subscribe to this entry?

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

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

Test script:
---------------
<?php
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:
----------------
bool(true)
bool(true)
bool(true)

Actual result:
--------------
bool(true)
bool(false)
bool(true)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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

  <?php 
  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: Mon Jan 30 21:03:49 2023 UTC