spl-autoload-register

Efficient PHP auto-loading and naming strategies

心已入冬 提交于 2019-11-27 04:10:15
问题 Like most web developers these days, I'm thoroughly enjoying the benefits of solid MVC architecture for web apps and sites. When doing MVC with PHP, autoloading obviously comes in extremely handy. I've become a fan of spl_autoload_register over simply defining a single __autoload() function, as this is obviously more flexible if you are incorporating different base modules that each use their own autoloading. However, I've never felt great about the loading functions that I write. They

PHP spl_autoload_register

自古美人都是妖i 提交于 2019-11-27 00:53:26
问题 I am trying to take advantage of autoloading in PHP. I have various classes in different directories, and so I have bootstrapped the autoloading as follows: function autoload_services($class_name) { $file = 'services/' . $class_name. '.php'; if (file_exists($file)) { require_once($file); } } function autoload_vos($class_name) { $file = 'vos/' . $class_name. '.php'; if (file_exists($file)) { require_once($file); } } function autoload_printers($class_name) { $file = 'printers' . $class_name. '