The Wayback Machine - https://web.archive.org/web/20201213001248/https://github.com/symfony/symfony-standard/pull/544
Skip to content
This repository has been archived by the owner. It is now read-only.

require <- require_once #544

Closed
wants to merge 2 commits into from
Closed

require <- require_once #544

wants to merge 2 commits into from

Conversation

@cordoval
Copy link
Contributor

@cordoval cordoval commented May 11, 2013

No description provided.

@cordoval
Copy link
Contributor Author

@cordoval cordoval commented May 11, 2013

@stof @fabpot awaiting for your insights here

@wouterj
Copy link
Member

@wouterj wouterj commented May 11, 2013

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

@cordoval
Copy link
Contributor Author

@cordoval cordoval commented May 11, 2013

@wouterj i am with you, there is a myth however that this optimizes OS disk hits, i am not sure if buying it yet but i wanted to hear from @fabpot and @stof and other vets

@@ -13,7 +13,7 @@
$loader->register(true);
*/

require_once __DIR__.'/../app/AppKernel.php';
require __DIR__.'/../app/AppKernel.php';

This comment has been minimized.

@stof

stof May 11, 2013
Member

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';

This comment has been minimized.

@stof

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)

@bamarni
Copy link
Contributor

@bamarni bamarni commented May 12, 2013

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.

@stof
Copy link
Member

@stof stof commented May 13, 2013

@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.

@bamarni
Copy link
Contributor

@bamarni bamarni commented May 13, 2013

@stof : I was talking about AppKernel / AppCache.

@fabpot
Copy link
Member

@fabpot fabpot commented May 25, 2013

Closing as there is no real benefit in changing this and it can potentially cause problems if people are not caution enough.

@fabpot fabpot closed this May 25, 2013
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.