Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
require <- require_once #544
Conversation
|
Why would you do this? What is the benefit of require? I can only see the good side of require_once: A file isn't loaded twice and we don't get 'cannot redeclare class' errors |
| @@ -13,7 +13,7 @@ | ||
| $loader->register(true); | ||
| */ | ||
|
|
||
| require_once __DIR__.'/../app/AppKernel.php'; | ||
| require __DIR__.'/../app/AppKernel.php'; |
stof
May 11, 2013
Member
For the class definition, I would keep the _once to be safe
For the class definition, I would keep the _once to be safe
| @@ -3,7 +3,7 @@ | ||
| use Symfony\Component\ClassLoader\ApcClassLoader; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
|
|
||
| $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; | ||
| $loader = require __DIR__.'/../app/bootstrap.php.cache'; |
stof
May 11, 2013
Member
Here, both have drawbacks:
- the bootstrap file contains classes so requiring it several times is a fatal error
- using require_once,
$loader will be null if it is already required, thus breaking the ApcClassLoader setup.
I guess the proper way to solve it would be to get the loader from vendor/autoload.php directly as the file generated by Composer is designed to be able to require it as often as needed (and returning the same loader each time)
Here, both have drawbacks:
- the bootstrap file contains classes so requiring it several times is a fatal error
- using require_once,
$loaderwill benullif it is already required, thus breaking the ApcClassLoader setup.
I guess the proper way to solve it would be to get the loader from vendor/autoload.php directly as the file generated by Composer is designed to be able to require it as often as needed (and returning the same loader each time)
|
Isn't the goal of autoloading to stop bothering with file inclusions before using classes? Here they could all be removed (front controllers, console, there is even a require_once in AppCache) and simply replaced by 2 lines in composer.json under a classmap section. |
|
@bamarni The goal of the bootstrap.php.cache file is to improve performance by loading classes used to boot the kernel (so needed all the time) without going through the PHP autoloading. |
|
@stof : I was talking about AppKernel / AppCache. |
|
Closing as there is no real benefit in changing this and it can potentially cause problems if people are not caution enough. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

No description provided.