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
31
votes
2 answers

multiple spl_autoload_register

what is/are the benefit(s) of having multiple spl_autoload_register example: spl_autoload_register('autoload_systems'); spl_autoload_register('autoload_thirdparties'); spl_autoload_register('autoload_services'); vs: using…
Gino Sullivan
  • 2,203
  • 18
  • 29
30
votes
2 answers

php spl_autoload_register vs __autoload?

hello is there any diffrence useing this excepts that we can use our own name auto load? is there any performance difference? how do they internally work? between function __autoload_libraries($class){ include_once…
Adam Ramadhan
  • 22,712
  • 28
  • 84
  • 124
30
votes
4 answers

Rails console: Unable to autoload constant

I have a Customer_ratings model that allows users to leave feedback on each other. The web app is working properly, and feedback is collected, stored and displayed. I wanted to go in and delete some feedback through the rails console, but when I…
dmt2989
  • 1,610
  • 3
  • 17
  • 30
29
votes
2 answers

Convert CamelCase to under_score_case in php __autoload()

PHP manual suggests to autoload classes like function __autoload($class_name){ require_once("some_dir/".$class_name.".php"); } and this approach works fine to load class FooClass saved in the file my_dir/FooClass.php like class FooClass{ …
P.M
  • 2,880
  • 3
  • 43
  • 53
26
votes
3 answers

Composer Autoload Multiple Files in Folder

I'm using composer in my latest project and mapping my function like this "require": { ... }, "require-dev": { ... }, "autoload": { "psr-4": { ... }, "files": [ "src/function/test-function.php" ] } I imagine…
Tiara Larasati
  • 335
  • 1
  • 4
  • 10
25
votes
4 answers

Composer classmap autoload does not load new files in folder

The following problem: I have defined a classmap in my composer.json: "autoload": { "classmap": [ "app/controllers", "app/models", "app/helper.php" ] } However, when I create a new file in the "controllers" or…
pyxl
  • 255
  • 1
  • 3
  • 5
23
votes
15 answers

Laravel: Controller does not exist

I added new controller in /app/controllers/admin/ folder and added the route in /app/routes.php file as well. Then i run the following command to autoload them php artisan dump-autoload I got the following error Mcrypt PHP extension required. I…
Neeraj
  • 8,625
  • 18
  • 60
  • 89
22
votes
1 answer

Recursively including all model subdirectories

How do you load all directories recursively in the models and lib directories? In application.rb, I have the lines: config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')] config.autoload_paths += Dir[Rails.root.join('lib',…
GTDev
  • 5,488
  • 9
  • 49
  • 84
21
votes
3 answers

Autoloading classes in Ruby without its `autoload`

I love the autoload functionality of Ruby; however, it's going away in future versions of Ruby since it was never thread-safe. So right now I would like to pretend it's already gone and write my code without it, by implementing the lazy-loading…
mislav
  • 14,919
  • 8
  • 47
  • 63
21
votes
4 answers

Codeigniter + Composer

I would like to start learning Codeigniter. But it seems that Codeigniter has not support for installation via Composer. When I search in Google I found this link. It seems that Codeigniter has not support for autoload.php file created by Composer.…
Čamo
  • 3,863
  • 13
  • 62
  • 114
21
votes
2 answers

Trait not found inside Laravel 5 unit tests

I'm writing some unit tests to test the API endpoints in my Laravel 5 application, and a lot of endpoints require user authentication. Instead of having the same user account creation code in every test, I wanted to define a RegistersUsers trait to…
John Dorean
  • 3,744
  • 9
  • 51
  • 82
20
votes
2 answers

How can I preload concerns in a rails initializer using Rails 6/Zeitwerk?

I'm working with an initializer that does some monkey patching on app start by including some app concerns into a third party lib. Basically: # config/initializers/my_initializer.rb class SomeExternalLib include MyConcern1 include…
Glyoko
  • 2,071
  • 1
  • 14
  • 28
20
votes
1 answer

PSR-4 autoloader Fatal error: Class not found

I have my project structure like so: src/ ├─ Model/ └─ User.php My User.php file looks like this:
JeremyKirkham
  • 1,025
  • 2
  • 11
  • 22
20
votes
1 answer

PSR-4 autoloading with Composer

I run a portail with composer's autoloading class system: "autoload": { "psr-4": { "Portal\\": "src/" } } It works when I run composer.phar dump -o, for instance my class Boostrap is well referenced into…
Fractaliste
  • 5,777
  • 11
  • 42
  • 86
20
votes
3 answers

Rails unable to autoload constant from file despite being defined in that file

This is a tricky one to explain. I have a module in another module namespace like so: # app/models/points/calculator.rb module Points module Calculator def self.included(base) base.send(:include, CommonMethods) base.send(:include,…
Peter P.
  • 3,221
  • 2
  • 25
  • 31