DEV Community

Discussion on: Why require files when you could autoload classes

Collapse
 
arxeiss profile image
Pavel Kutáč

There are cases when require makes sense more than autoload. And I think it is not so known.

// file called config.php
return [ 'app_key' => 'some_value_for_app_key' ];
Enter fullscreen mode Exit fullscreen mode
$cfg = require 'config.php';
echo $cfg['app_key']; // Will print out some_value_for_app_key
Enter fullscreen mode Exit fullscreen mode
Collapse
 
andersbjorkland profile image
Anders Björkland

Good point!
Yeah, I mostly code with classes where I haven't needed to do these things. Symfony does it for me 🤔 The exception is when I use Deployer. It's require-calls to sundown!