autoload

Strange PHP autoload issue

无人久伴 提交于 2019-12-10 17:41:31
问题 I have some method which looks like that public function getTime() { $date = new DateTime(); $date->setTimezone(new DateTimeZone('Europe/Paris')); return $date->format('Y-m-d H:i:s'); } Calling this method from inside file which has autoload function function __autoload($class_name) { global $path; if (file_exists($path['classes'] . ds . 'class.'. $class_name . '.php')) { require_once($path['classes'] . ds . 'class.'. $class_name . '.php'); } else { die($path['classes'] . ds . 'class.'.$class

Kohana 3 Auto loading Models

 ̄綄美尐妖づ 提交于 2019-12-10 17:37:26
问题 I'm attempting to use a Model but I get a fatal error so I assume it doesn't autoload properly. ErrorException [ Fatal Error ]: Class 'Properties_Model' not found The offending controller line: $properties = new Properties_Model; The model: class Properties_Model extends Model { public function __construct() { parent::__construct(); } } I also put the class in three different locations hoping one would work, all there failed. They are: application/classes/model application/model application

Does PHP namespace autoloading have to use folders?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 13:57:40
问题 I am quite confused in implementing namespace in php, especially when it comes to alias - importing classes. I have followed the tutorial from this tutorial: Leveraging PHP V5.3 namespaces for readable and maintainable code (by Don Denoncourt; 1 Mar 2011; for IBM Developerworks) But I don't understand - when __autoload is used, why I have to store the alias classes in folders, but when __autoload is not used, the alias in namespace are just fine, like this below, <?php namespace barbarian;

CodeIgniter lazy-loading libraries/models/etc

混江龙づ霸主 提交于 2019-12-10 10:54:01
问题 When writing CodeIgniter applications my controller actions tend to begin with a few lines as below: $this->load->model('abc_model'); $this->load->library('ijk'); And then (just for completeness) they're used as follows: $this->abc_model->fetch_123(); $this->ijk->do_something(); Would there be anything too wrong about extending MY_Controller so that the following was possible? $this->model('zbc_model')->fetch_stuff(); $this->library('ijk')->do_something(); Pros: Classes aren't loaded until

Zend Framework 2: Composer\Autoload\includeFile is slow

喜夏-厌秋 提交于 2019-12-10 04:51:59
问题 According to New Relic transaction tracer, sometimes Composer\Autoload\includeFile takes around 318 ms to load my project. I have dumped a classmap from composer, but still no difference it made. composer.json requires the following: "require": { "php": ">=5.3.3", "zendframework/zendframework": "2.4.*", "zendframework/zendservice-amazon": "2.*", "wisembly/elephant.io": "~3.0", "knplabs/github-api": "~1.2" } I only have one module in my ZF2 application. How can my ZF2 autoloading perform

Are there performance downsides while using autoloading classes in PHP?

拟墨画扇 提交于 2019-12-10 01:54:46
问题 Currently I load in all my classes by including a "all.inc.php" file on every page of my site, this file then goes on to include all the config, classes, functions, etc. that I will use on the whole site. My issue with this is that often I use classes that only pertain to certain pages/sections of a website, so often I am including a bunch of classes at the start of the page which will not be used. Obviously autoloading the classes would fix this issue, so my question is, would autoloading

How can I load classes from multiple directories with __autoload?

戏子无情 提交于 2019-12-09 19:14:32
问题 Following up on this question, it seems that the duplicate issue could be solved by just using the __autoload code below, function __autoload($class_name) { include AP_SITE."classes_1/class_".$class_name.".php"; } $connection = new database_pdo(DSN,DB_USER,DB_PASS); var_dump($connection); result, object(database_pdo)[1] protected 'connection' => object(PDO)[2] but this only loads the classes from one directory, what about other directories? Because I group the classes in different directories

Composer autoload always comes first

核能气质少年 提交于 2019-12-09 03:50:26
I'm using composer in a legacy project that have lots of classes with no namespace. Refactoring is not an option (it's a very huge application), but all new modules are fully psr-4 compliant. The legacy code has it's own autoload method (using a class map, pretty efficient). My problem is: no matter in which order I add the autoloader methods, composer autoloader ALWAYS COMES FIRST! This is slowing down the load of each single class: every time I call a class from the legacy code, it first tries to match it against all composer autoload options (including the findFileWithExtension() ), and

Codeigniter - An Error Was Encountered - Unable to load the requested class: encrypt

被刻印的时光 ゝ 提交于 2019-12-08 13:50:15
问题 I have inherited a CI v2.0.2 project. For development purposes, the project was moved to another subdomain, and the database.php file has been properly reconfigured. The login page loads fine. However, after trying to login, I get an error from CI saying: An Error Was Encountered Unable to load the requested class: encrypt In autoload.php , the database and session libraries are autoloaded. This file is the same as in the main codebase. If I add the encrypt library in the above line, I’m

How to include third party lib in Zend Framework 2

亡梦爱人 提交于 2019-12-08 13:30:58
问题 I'm migrating application from ZF1 to ZF2. I have a controller depends on third party lib 'Solarium'. namespace Stock\Controller; class BaseController extends AbstractActionController { protected function indexAction() { require_once('Solarium/Autoloader.php'); Solarium_Autoloader::register(); The 'Solarium' exists under 'vendor', and in 'init_autoloader.php' I have: set_include_path(implode(PATH_SEPARATOR, array( realpath('vendor') ))); But, when I viewing the page, there's an error: Fatal