Skip to content

Commit

Permalink
2.0.1 regression
Browse files Browse the repository at this point in the history
errorHandler 'onShutdown' handler inadvertently registered after the output 'onShutdown' handler... (fatal errors being logged after output occurs)  :(
Fix:
 * errorHandler now subscribing to 'php.shutdown' via eventManage (with higher than default priority for good measure) - was using register_shutdown_function()
 * added unit test to assert that errorHandler::onShutdown subscriber is before internal::onShutdown
  • Loading branch information
bkdotcom committed Feb 2, 2018
1 parent ac03fb7 commit bfae314
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Debug/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function __construct(EventManager $eventManager, $cfg = array())
}
$this->setCfg($cfg);
$this->register();
// there's no method to unregister a shutdown function
// so, always register, and have shutdownFunction check if "registered"
register_shutdown_function(array($this,'onShutdown'));
// easier to maintain subscription to php.shutdown event and check this->registered value
// than to subscribe with register() and unsub with unRegister()
$this->eventManager->subscribe('php.shutdown', array($this, 'onShutdown'), 1);
return;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/DebugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ protected function checkAbstractionType($var, $type)
return $return;
}

/**
* Test that errorHandler onShutdown occurs before internal onShutdown
*
* @return void
*/
public function testShutDownSubscribers()
{
$subscribers = $this->debug->eventManager->getSubscribers('php.shutdown');
$this->assertSame($this->debug->errorHandler, $subscribers[0][0]);
$this->assertSame('onShutdown', $subscribers[0][1]);
$this->assertSame($this->debug->internal, $subscribers[1][0]);
$this->assertSame('onShutdown', $subscribers[1][1]);
}

/**
* Test
*
Expand Down

0 comments on commit bfae314

Please sign in to comment.