php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #28333 class_exists call __autoload
Submitted: 2004-05-09 08:22 UTC Modified: 2004-07-02 05:05 UTC
From: e_corge at yahoo dot fr Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0RC2 OS: *
Private report: No CVE-ID: None
 [2004-05-09 08:22 UTC] e_corge at yahoo dot fr
Description:
------------
I've a function __autoload in my script. I want to use class_exists to determine if a class definition has been included but i don't want to load it.

However, class_exists call __autoload systematically when a class definition hasn't been loaded.

This problem poses problems of compatibility with previous versions.  Indeed, many scripts used this function before using a include.

Reproduce code:
---------------
function __autoload($classname) {
  echo 'i want to load ['.$classname.']<br>';
}

class A {}

if (class_exists('B') == false) 
  echo "Class B don't exist !<br>";
else
  echo "Class B exist !<br>";

if (class_exists('A') == false) 
  echo "Class A don't exist !<br>";
else
  echo "Class A exist !<br>";


Expected result:
----------------
Class B don't exist !
Class A exist !


Actual result:
--------------
i want to load [B]
Class B don't exist !
Class A exist !


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-09 13:01 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.
 [2004-05-09 13:02 UTC] helly@php.net
Head version supports a second parameter for excatly that reason. If that parameter is 'false' then no __autoload is being called.
 [2004-07-01 06:35 UTC] curt@php.net
this needs to be added to documentation
bool class_exists(string classname, [bool autoload])
 [2004-07-02 05:05 UTC] curt@php.net
Fixed in cvs.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC