Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] fixed kernel re-init (when getting unserialized for eg.) #6326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpKernel] fixed kernel re-init (when getting unserialized for eg.)
When a kernel object gets unserialized, it's being constructed, then
initialized, there shouldn't be any need to call the init method
twice in a process, it basically only contains static calls
affecting some PHP ini settings or error handlers, actually it can lead
to unexpected things if it's called more than once, for eg. having
duplicate error messages or registering DebugClassLoaders for
DebugClassLoaders.

Imo this method shouldn't even be publicly accessible, but I didn't
wanted to break things.
  • Loading branch information
bamarni committed Dec 13, 2012
commit 58b6f98461de061c0d59d8bd29e0fafd6e96d955
26 changes: 16 additions & 10 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ abstract class Kernel implements KernelInterface, TerminableInterface
protected $startTime;
protected $classes;
protected $errorReportingLevel;
protected $initialized = false;

const VERSION = '2.2.0-DEV';
const VERSION_ID = '20100';
Expand Down Expand Up @@ -95,18 +96,22 @@ public function __construct($environment, $debug)

public function init()
{
ini_set('display_errors', 0);
if (!$this->initialized) {
ini_set('display_errors', 0);

if ($this->debug) {
error_reporting(-1);

DebugClassLoader::enable();
ErrorHandler::register($this->errorReportingLevel);
if ('cli' !== php_sapi_name()) {
ExceptionHandler::register();
} else {
ini_set('display_errors', 1);
if ($this->debug) {
error_reporting(-1);

DebugClassLoader::enable();
ErrorHandler::register($this->errorReportingLevel);
if ('cli' !== php_sapi_name()) {
ExceptionHandler::register();
} else {
ini_set('display_errors', 1);
}
}

$this->initialized = true;
}
}

Expand Down Expand Up @@ -754,6 +759,7 @@ public function unserialize($data)
{
list($environment, $debug) = unserialize($data);

$this->initialized = true;
$this->__construct($environment, $debug);
}
}