Question

I have got a class which is called "BaseCore" which just runs all the spl_autoload_registers(); which are in that file.

class BaseCore{

public function __construct(){
    spl_autoload_register( 'loadClasses' );   
    spl_autoload_register( 'loadConfig' );
    spl_autoload_register( 'loadFMAPI' );
}

My second class extends BaseCore which on every new class that I want to extend the BaseCore, I have to require/include the BaseCore class.

require_once( 'classes/baseCore.class.php' );

class SchedulerDND extends BaseCore {

However, this seems very obsolete and an old way to do this.

So I guess my question is, how would I include the BaseCore into my child-class without having to write require_once(); on every child-class?

Thanks!

Was it helpful?

Solution

All you spl_autoload_register classes should be in some type of bootstrap file For example create bootstrap.php and put all your autoload calls there. Then you would make sure you always include your bootstrap file For example, require 'bootstrap.php' in your index.php

That's all there is to it. You bootstrap.php is loaded only once then you able to rely on autoloader to load all your classes, no need to have require or require_once in any of your classes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top