# __autoload() and class_exists()

- Thread: https://externals.io/message/15153
- Original archive: https://news-web.php.net/php.internals/15153
- Started by Stephan Schmidt on 2005-02-22T19:59:27+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15153 — Stephan Schmidt — 2005-02-22T19:59:27+00:00

URL: https://externals.io/message/15153#15153

Hi,

I just found this strange behaviour in PHP5:

When using `class_exists()` to test, whether a class exists, the magic 
function __autoload() is called:

function __autoload($class)
{
   echo "Trying to load $class\n";
}

if (!class_exists('DB')) {
   echo "DB does not exist.\n";
}

You'll get:

Trying to load DB
DB does not exist.

Is this a bug or the desired behaviour? It's pretty annoying, when you 
are trying to use __autoload() as a fallback if a class could not be 
loaded from directories defined by the user...

Best regards,

Stephan
-- 
http://www.php-tools.net
http://www.schst.net
http://pear.php.net

---

## #15154 — Marcus Boerger — 2005-02-22T20:08:00+00:00

URL: https://externals.io/message/15153#15154 · In reply to: #15153

Hello Stephan,

Tuesday, February 22, 2005, 8:59:27 PM, you wrote:

> Hi,

> I just found this strange behaviour in PHP5:

> When using `class_exists()` to test, whether a class exists, the magic 
> function __autoload() is called:

Expected behavior that can be changed:

proto bool class_exists(string classname [, bool autoload])

"RTFM" or is it undocumented?

Best regards,
 Marcus                            mailto:helly@php.net

---

## #15156 — Stephan Schmidt — 2005-02-22T20:09:51+00:00

URL: https://externals.io/message/15153#15156 · In reply to: #15154

Hi,

Marcus Boerger schrieb:
> Expected behavior that can be changed:
> 
> proto bool class_exists(string classname [, bool autoload])
> 
> "RTFM" or is it undocumented?

Ooops, didn't check the manual for `class_exists()` in the last months...

Stephan
-- 
http://www.php-tools.net
http://www.schst.net
http://pear.php.net
