There is a variable:

private $_classes = [ 'Component' => '/base/Component.php', 'Controller' => '/kernel/Controller.php', 'DataBase' => '/kernel/DataBase.php', ]; 

And there is a function that connects all these files and creates an object instance for each file:

 public function autoload() { foreach ($this->_classes as $key => $value) { $path = base_url . $value; if (file_exists($path)) { require_once $path; return new $key; } } } 

However, for some reason, this code is executed only once and that's it. If you remove

 return new $key 

That's all fine, all 3 classes are included.

Tell me which way to dig?

  • because the method ends with return during the first iteration - etki

1 answer 1

PHP does not know, but the campaign is satisfied with the condition file_exists($path) at the first iteration and the function is exited in the if construct on the line

 return new $key;