autoload

How do I NOT autoload a class in php?

[亡魂溺海] 提交于 2019-12-07 14:13:47
问题 the autoloader at the beginning of my php code function __autoload($class_name) { include_once $class_name . '.class.php'; } is causing a call to new MongoClient(); to fail with the error Warning: include_once(MongoClient.class.php): failed to open stream How can I use the autoloader for my classes and still use the standard classes? Note: MongoDb has been installed with PECL and works fine with the autoloading function removed. mongo-1.3.0beta2 on php 5.4.9 回答1: __autoload() , if defined, is

Import package or autoloading for PHP?

為{幸葍}努か 提交于 2019-12-07 08:59:01
问题 What solution would you recommend for including files in a PHP project? There aren't manual calls of require/include functions - everything loads through autoload functions Package importing, when needed. Here is the package importing API: import('util.html.HTMLParser'); import('template.arras.*'); In this function declaration you can explode the string with dots (package hierarchy delimeter), looping through files in particular package (folder) to include just one of them or all of them if

Autoload with namespaces in PHP 5.3?

拜拜、爱过 提交于 2019-12-06 17:42:54
问题 How do you use _autoload in PHP 5.3 with namespaces? I have a main autoload function in a namespace separate from my script. I'm also calling a class with a different namespace. (It's not surprising, but) It's not finding the autoload function. Do I have to recreate the autoload function for each namespace? That seems suboptimal. Thanks in advance for any help! 回答1: From a comment in the PHP manual: To use autoload function with namespaces you should remember to define it in main scope in "\"

Using the PHP spl_autoload_register() with Codeigniter

主宰稳场 提交于 2019-12-06 14:11:38
问题 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

Creating new service providers in Silex

时光怂恿深爱的人放手 提交于 2019-12-06 12:58:58
I've been using Silex for a while now without any issues. I've been able to add new services, create basic sites, etc. Unfortunately I'm stuck now on creating a new service from scratch... I'm not too sure what I'm doing wrong and I figured a nudge in the right direction would be useful right about now. I have a basic structure like this: cache resources src -app.php -autoload.php -config.php -controllers.php -etc vendor -assetic -Company -src -Postback.php <-- The classes I need to load -silex -etc views web So, in app.php : use SilexExtension\CompanyPostbackServiceProvider; $app->register

Autoloader resulting in class not found

╄→尐↘猪︶ㄣ 提交于 2019-12-06 11:29:11
问题 I am trying to include an autoloader in my wordpress project. More specifically, I am developing a plugin that contains a Classes/ directory of all my classes. I want these classes to be accessible by namespace to my wordpress project root and children files/folders. I feel like my composer.json should take care of the autoloader implementation, although I am still getting a Class not found fatal error. Has anyone else run into this issue? I appreciate any suggestions in advance! This is what

CodeIgniter lazy-loading libraries/models/etc

纵然是瞬间 提交于 2019-12-06 11:26:39
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 they're actually used Wouldn't need to auto-load any classes using config/autoload.php Slightly cleaner

Autoloaders in PHP - two running at a time

泪湿孤枕 提交于 2019-12-06 09:05:43
I understand how to register autoloaders and even how to create one, that's no issue at all. How ever the main issue is - how do you have two auto loaders running side by side for something like: class project_one_folder_class extends project_two_folder_class{} You'll notice that the child class belongs to a project which is reaching out and calling the parent class which is locate in a different project. The way the projects are linked project two's classes are always seen by the auto loader, how ever project one's classes are never seen. So the way I thought around this was to write two auto

How to manage dependency autoloading

徘徊边缘 提交于 2019-12-06 06:02:09
问题 When building a library I always provide an Autoloader class that handles autoloading for the library. The autoloader is registered like this: require_once 'path/to/PHP-Parser/lib/PHPParser/Autoloader.php'; PHPParser_Autoloader::register(); I'm not sure though how to handle it if my library depends on another library. Imagine that PHPParser depends on a PHPLexer . Now when using the library one would need to write: require_once 'path/to/PHP-Lexer/lib/PHPLexer/Autoloader.php'; PHPLexer

Rails unable to autoload constant only on first attempt

a 夏天 提交于 2019-12-06 06:01:44
In my Rails 4 app, I have a base model, let's call it Badge, which lives in /app/models/badge.rb . Then, I have a large number of specific badges that inherit from Badge, let's say GoldBadge and SilverBadge (and many more, in reality). All of these files live in /app/model/badge/<name>_badge.rb . For example, /app/model/badge/gold_badge.rb . The class declaration for GoldBadge would look like this class GoldBadge < Badge ... However, the Rails (or Ruby, I don't really know) auto-loader, has trouble locating these files only on the first attempt . What I mean by that is when I first access a