It is not clear what you decided (and everyone believed) that you need a magician. __get
method when it comes to attaching files.
Autoloader needed:
<?php // или так: function my_autoloader($class) { include 'classes/' . $class . '.php'; } spl_autoload_register('my_autoloader'); // или так: // function __autoload($class) { // include 'classes/' . $class . '.php'; // } ?>
After adding this code, the required file from the "classes" directory will be included, provided that it is correctly named. For example, you create an instance of the map
class:
<? $map = new map(); $map->some_method(); ?>
So, if there was no class declaration at this point, an attempt will be made to connect the "./classes/map.php" file in the hope that the required class is described in it.
Read more: PHP OOP5 - autoload
UPD
That is, if you want to get an object of the class map
when you call $vasek->map
map
, you need to add your classes to the $classes
array. It is strange why this is done in this way, but what is, that is. I, for example, just checked for the presence of the file of the same name. But you need this:
class vasek { private $classes = array( 'config' => 'Config', 'request' => 'Request', 'map' => 'Map', ); ... }
and then - move the file "map.php" to "api / Map.php" (follow the register!).
Then at the first call to $vasek->map
file "api / Map.php" will be connected, an instance of the class will be created: new Map()
and saved in the closed $objects
array - so that when you next access this message, you’ll return to the already created an object.