ElkArte Community

Project Support => General ElkArte discussions => Topic started by: emanuele on January 30, 2021, 10:21:39 am

Title: class_exists
Post by: emanuele on January 30, 2021, 10:21:39 am
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);
}
etc.

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?
Title: Re: class_exists
Post by: Spuds on February 02, 2021, 08:40:52 pm
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.