spl-autoload-register

spl_autoload_register issue while loading class

妖精的绣舞 提交于 2019-12-05 20:17:35
So I already asked this question here earlier, but the solutions provided didn't work for me. Here's my setup: /mylib /Vendor/Module/MyClass.php /document_root index.php Here's my index.php <?php define('CLASSDIR', 'mylib'); define('BASEPATH', @realpath( dirname (__FILE__).'/../').'/'.CLASSDIR); spl_autoload_register(null, false); spl_autoload_extensions('.php'); function autoLoader($className){ $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { echo 'does it come here? nope.'; $namespace = substr($className, 0, $lastNsPos);

Using the PHP spl_autoload_register() with Codeigniter

瘦欲@ 提交于 2019-12-04 18:59:44
Please how can I use spl_autoload_register() with Codeigniter? I need to do this because Im using Codeigniter with another framework which also uses autoload. I saw something here PHP spl_autoload_register but I dont know how to target the CodeIgniter autoload . Im new to OOP and Codeigniter. Thanks a lot! The above link has this: 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

What's the principle of autoloading in PHP?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 14:52:18
问题 spl_autoload_register can do this kind of job,but I don't understand how is that kind of job done? spl_autoload_register(array('Doctrine', 'autoload')); 回答1: The basic idea is that you don't have to write include / require instructions anymore : whenever you're trying to use a non-defined class, PHP will call the autoloader. The job of the autoloader, then, is to determine which file should be loaded, and include it, so the class becomes defined. PHP can then use that class, as if you were

multiple spl_autoload_register issue

浪尽此生 提交于 2019-12-04 10:52:04
问题 I'm working on the development of a custom framework. And I have encountered an issue when I tried to dynamise the calling of my classes. This is a visual of my files : So I decided to create a different function for each folder (libs, controllers et modeles): function autoloadLibs($class) { //require the general classes require 'libs/' . $class . '.php'; } function autoloadModels($class) { //require the models classes require 'models/' . $class . '.php'; } function autoloadControllers($class

What's the principle of autoloading in PHP?

我怕爱的太早我们不能终老 提交于 2019-12-03 10:16:06
spl_autoload_register can do this kind of job,but I don't understand how is that kind of job done? spl_autoload_register(array('Doctrine', 'autoload')); The basic idea is that you don't have to write include / require instructions anymore : whenever you're trying to use a non-defined class, PHP will call the autoloader. The job of the autoloader, then, is to determine which file should be loaded, and include it, so the class becomes defined. PHP can then use that class, as if you were the one who wrote the include instruction, that has in fact been executed in the autoloading function. The

How to use spl_autoload_register for multiple diectories in PHP?

强颜欢笑 提交于 2019-12-03 02:10:13
问题 I'm actually trying to create a MVC framework for my own, however I'm having troubles with the Autoload. It's not a problem actually, but I'd like to ask the gurus, how are they using the spl_autoload_register function when there are different directories. Lets say we have the following directories: Controllers Libs Models Each folder contains different classes, like: Controllers: Main.php File.php About.php Libs: Main.php Front_controller.php Models: Index.php File.php Login.php You can

How to use spl_autoload_register for multiple diectories in PHP?

纵饮孤独 提交于 2019-12-02 17:11:22
I'm actually trying to create a MVC framework for my own, however I'm having troubles with the Autoload. It's not a problem actually, but I'd like to ask the gurus, how are they using the spl_autoload_register function when there are different directories. Lets say we have the following directories: Controllers Libs Models Each folder contains different classes, like: Controllers: Main.php File.php About.php Libs: Main.php Front_controller.php Models: Index.php File.php Login.php You can notice that some file names might be found with the same name in different directories. Okay, so this is

PHP Autoloading in Namespaces

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 06:34:52
I have had a slight problem with autoloading in my namespace. As shown on the PHP manual here: http://us.php.net/manual/en/language.namespaces.rules.php you should be able to autoload namespace functions with a full qualified name e.g. \glue\common\is_email(). Thing is I have a function spl_autoload_register(array($import, "load")); within the initial namespace but whenever I try and call \glue\common\is_email() from the initial namespace it will not pass that autoload function but when using new is_email() (in the context of a class) it will. I don't get it the manual says I can autoload from

PHP spl_autoload_register

这一生的挚爱 提交于 2019-11-28 05:19: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. '.php'; if (file_exists($file)) { require_once($file); } } spl_autoload_register('autoload_services');

Efficient PHP auto-loading and naming strategies

隐身守侯 提交于 2019-11-27 16:58:24
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 involve a lot of string checking and directory scanning in order to look for possible classes to load. For