autoload

PHP __autoload() with namespace

不问归期 提交于 2019-12-08 11:42:38
问题 spl_autoload_register('Think\Think::autoload'); Under namespace Think\ I created the above register function,when I try to use a class that has not been included like class Storeage,php will surposely pass Storeage as the variable to function Think\Think::autoload,but it actually passed Think\Storeage as the variable,why it adds the extra Think\ to the autoload instead of just Storeage? Does that mean autoload will only search for classes which are declared under the same namespace where the

Why can't I access some library classes when I'm in a thread?

最后都变了- 提交于 2019-12-08 11:17:45
问题 Why does the following require "bio" threads = (1..2).map do Thread.new do seqs = ["gattaca"] * 5 alignment = Bio::Alignment.new(seqs) end end threads.each {|th| th.join} ; nil give this error message? NameError: uninitialized constant Bio::Alignment from (irb):6 from (irb):10:in `join' from (irb):10 from (irb):10:in `each' from (irb):10 回答1: The bioruby library (or at least some versions of it) use autoload. Autoload isn't thread-safe (at least in ruby 1.8), so if two threads are accessing

php autoload: duplication of db connection

痞子三分冷 提交于 2019-12-08 10:47:08
问题 Why does this autoload class duplicate the db connection? class autoloader { private $directory_name; public function __construct($directory_name) { $this->directory_name = $directory_name; } public function autoload($class_name) { $file_name = 'class_'.strtolower($class_name).'.php'; $file = AP_SITE.$this->directory_name.'/'.$file_name; if (file_exists($file) == false) { return false; } include ($file); } } # nullify any existing autoloads spl_autoload_register(null, false); # specify

Auto redirecting to another pages at regular intervels

孤街浪徒 提交于 2019-12-08 06:45:57
问题 I want to create an application in PHP. concept is very simple, I want to just auto load every page randomly at a regular intervals. For example, if i entered to facebook.com , it would be auto load randomly profile.php, notifications.php, messages.php etc... I am not sure about its practicality. So my question may be stupid, but i need help.I only know meta refresh which is only for refreshing the page. <meta http-equiv="refresh" content="5; url=http://example.com/"> But i think, using the

Composer autoload always comes first

余生颓废 提交于 2019-12-08 04:43:12
问题 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

Rails unable to autoload constant only on first attempt

杀马特。学长 韩版系。学妹 提交于 2019-12-08 02:05:56
问题 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

Autoloaders in PHP - two running at a time

你离开我真会死。 提交于 2019-12-07 21:56:54
问题 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

Creating new service providers in Silex

删除回忆录丶 提交于 2019-12-07 18:58:10
问题 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

Doctrine, namespace and autoload entities

匆匆过客 提交于 2019-12-07 17:05:48
问题 I want to use Doctrine 2 in my project. I've some problems with it. I read the docs but probably I'm doing something wrong. I want to autoload entities classes. And method from the docs is not working. My bootstrap.php <?php require_once "vendor/autoload.php"; use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\Driver; $paths = array("../Entities"); $isDevMode = false; $classLoader = new \Doctrine\Common\ClassLoader('Entities','../Entities'); $classLoader-

Autoloading functions best practices

蓝咒 提交于 2019-12-07 14:42:20
问题 When working on a PHP project that takes advantage of the OOP paradigm with PHP's __autoload() function, which of the following is considered the best practice for managing stand-alone functions: ( Examples provided are simplified for the sake of brevity ) tl;dr : How is stand-alone function loading commonly handled: pseudo-autoloading (via __callStatic magic for example) [ Option 1 ] abstract helper class grouped static methods [ Option 2 ] an alternative Also note, I've posted a related