Question

I know symfony can autoload files with spl_auto_register,but is it clever enough?

If only a.php is needed to load,will it also load b.php?

Was it helpful?

Solution

The autoloader will only load the files necessary to instantiate a requested class.

OTHER TIPS

The autoloader works by storing an array of key value pairs such that

classname => /full/path/to/class

In symfony 1.3/1.4 two cache files get created. One for the core classes, created by sfCoreAutoload, and stored in /cache/project.autoload. For the classes that are autoloaded from within your project directory, the array of key value pairs is stored in /cache/_app_/_env_/config/config_autoload.yml.php. This file is generated by the config handler sfAutoloadConfigHandler.

Some useful points to remember:

  • Not all classes within your project are autoloaded, the autoloaded files are specified by autoload.yml (in sf_lib_dir/config/config). You can create your own autoload.yml and drop it into the project config dir (or even application config dir I think).
  • When running in dev environment, if a class cannot be autoloaded then symfony will rebuild the autoload cache hoping to find the file its assuming is new. This can make your app slow in certain use cases so use sfAutoloadAgain::unregister().
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top