Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Оба автозагрузчика грузят только те классы, которые присутствуют (объявлены new) в этом php-файле
- */
- define('DIR', __DIR__);
- define('APP', DIR.'/app');
- // Устаревший вариант
- function __autoload($class) {
- include APP. '/'. $class . '.php';
- }
- // Современный вариант с безымянной функцией
- spl_autoload_register(function ($class) {
- include APP. '/' . $class . '.php';
- });
- $obj1 = new MyClass1();
- $obj1->displayVar();
- ######### Файл MyClass1.php в папке app #########
- class MyClass1
- {
- // объявление свойства
- public $var = 'Мой класс 1';
- // объявление метода
- public function displayVar() {
- echo $this->var;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement