Skip to main content
Topic: class_exists (Read 3698 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.


I am playing (again... *sigh*) with the db code, and found some instances of things like:
Code: [Select]
		if (class_exists('\\ElkArte\\Errors\\Errors'))
Errors::instance()->log_error($log_message, 'critical', $file, $line);

if (class_exists('\\ElkArte\\Exceptions\\Exception'))
throw new Exception([false, $error_message], false);

hmm...:thinking: (for when emoji will be a thing :P )
If we made it to the database, we already have the autoloader available.
If we have the autoloader available, the class can be loaded.
Am I wrong?
If this is right, the the only case I can think of in which the class may not exist is if it is missing from the file system...
Because even for integration with other codebases (e.g. via bootstrap) we do have the autoloader so we must have the classes.

Am I missing something obvious?
Bugs creator.
Features destroyer.
Template killer.

Re: class_exists

Reply #1
I think you are correct ... those checks should not be necessary.   Does class_exist invoke the autoloader as well, for some reason I recall that it does.   Anyway it should be fine to just run the commands.
Be safe, Be kind, Happy Programing