Questions tagged [autoload]

autoload is a language convention which allows missing classes or method dependencies to be loaded on-demand.

autoload is implemented differently among languages which include it:

  • Perl's AUTOLOAD allows you to dynamically interpret method calls.
  • PHP's __autoload loads classes. To handle missing methods, the __call() magic method may be used.
  • Ruby's autoload command loads modules.
1633 questions
19
votes
1 answer

Composer Autoloading classes not found

I have folder structure like: includes/ libraries/ Classes/ Contact/ Contact.php ContactController.php admin/ controllers/ contact/ edit.php Contact.php is my class that file that I'm trying to use. The file…
Ryan Hipkiss
  • 648
  • 1
  • 7
  • 20
19
votes
3 answers

How to autoload classes without namespaces with Composer without reinstalling?

I just need to autoload some classes, and I don't like the psr-0 namespace insanity (no offense). This used to work just fine in my project: "psr-0": { "": [ "app/controller/", "app/model/" ] } For some reason it doesn't…
ChocoDeveloper
  • 14,160
  • 26
  • 79
  • 117
19
votes
7 answers

PHP - most lightweight psr-0 compliant autoloader

I have a tiny application that i need an autoloader for. I could easily use the symfony2 class loader but it seems like overkill. Is there a stable extremely lightweight psr-0 autloader out there?
Marty Wallace
  • 34,046
  • 53
  • 137
  • 200
18
votes
3 answers

Creating object from variable using Namespaces and Autoload in PHP

EDIT with my own comment afterwards I think the problem is that when PHP is parsing the file to "compile", first it translates class names to their fully qualified name. So Index will be translated to Controller\Home\Index. After that, is when…
Jose Armesto
  • 12,794
  • 8
  • 51
  • 56
18
votes
1 answer

How to detect if a class does not exist without triggering an error

I have run into an interesting dilema. In a DataMapper class, I am generating a class name to be used for returned rows from a database. The thing is, all of my classes are autoloaded, and can come from many places (library, application/models,…
FallenAvatar
  • 4,079
  • 1
  • 21
  • 24
17
votes
1 answer

How to create a PSR-4 autoloader for my project?

I am creating a PHP project and want to implement PSR-4 autoloading. I don't know which files I need to create in the vendor directory to implement autoloading for class files.
Kshitij Verma
  • 617
  • 1
  • 4
  • 12
17
votes
1 answer

How to use Composer to autoload classes from outside the vendor?

I use psr-4 autoloader from composer: "autoload": { "psr-4": { "DG\\Munchkin\\": "src/DG/Munch/" } } This loads classes from /var/www/html/xxx/vendor/yyy/src/DG/Munch But how can I load classes from /var/www/html/xxx/? I wrote my…
Tomasz Szymanek
  • 499
  • 2
  • 7
  • 18
17
votes
2 answers

php5.4 autoloading traits

Are traits in php5.4 subject to autoloading? I've not yet got an environment to test in, but I can't see any mention of it on __autoload at php.net or on the traits page, but it seems traits behave like classes in some regards. Has anyone tried this…
MyStream
  • 2,533
  • 1
  • 16
  • 33
16
votes
3 answers

emacs23 / elisp: how to properly autoload this library?

I am upgrading to emacs23. I find that my emacs.el loads much more slowly. It's my own fault really... I have a lot of stuff in there. So I am also trying to autoload everything possible that is currently "required" by my emacs.el. I have a…
Cheeso
  • 189,189
  • 101
  • 473
  • 713
16
votes
5 answers

Auto-load a module on python startup

I want IPython or the Python interpreter to auto-load a module when I start them. Is it possible? For example when I start IPython: $ ipython ... >>> from __future__ import division >>> from mymodule import * In [1]: Something like SymPy's…
rubik
  • 8,814
  • 9
  • 58
  • 88
16
votes
2 answers

PHP autoload and static variable in function

=== Base.php ===
Jelly
  • 189
  • 5
15
votes
2 answers

PHP autoloader class vs. procedural autoloader function?

Up to this point I've used procedural standalone autoloader functions and registered them with spl_autoload_register() to automatically load my (usually) namespaced classes. Lately, though, I've noticed people mentioning the use of autoloader…
user895378
15
votes
1 answer

With 'autoload' being deprecated, what should devs use in the meantime?

Having read a couple weeks ago that autoload is officially deprecated, Matz discourages use of it. What is to replace it? What should developers do instead? I used it in some command-line gems to save unnecessary loading of libs that may never be…
Nick Klauer
  • 5,893
  • 5
  • 42
  • 68
15
votes
3 answers

Is autoload thread-safe in Ruby 1.9?

It seems to me that the Ruby community has been freaking out a little about autoload since this famous thread, discouraging its use for thread safety reasons. Does anyone know if this is no longer an issue in Ruby 1.9.1 or 1.9.2? I've seen a bit of…
SFEley
  • 7,660
  • 5
  • 28
  • 31
15
votes
3 answers

How to list all autoload paths in Rails

How do you list all of the autoload paths in Rails? In Rails console when I do this, it only lists the custom paths added to the config: $ rails c Loading development environment (Rails 3.2.9) 1.9.3p194 :001 >…
Gary S. Weaver
  • 7,966
  • 4
  • 37
  • 61