In the example found at >> https://akrabat.com/overriding-slim-3s-error-handling/
pasted below for easy access :
###==============================
Overriding Slim 3’s error handling ( Copy Pasted )
$container = $app->getContainer();
$container['errorHandler'] = function ($container) {
return function ($request, $response, $exception) use ($container) {
// retrieve logger from $container here and log the error
$response->getBody()->rewind();
return $response->withStatus(500)
->withHeader('Content-Type', 'text/html')
->write("Oops, something's gone wrong!");
};
};
$container['phpErrorHandler'] = function ($container) {
return function ($request, $response, $error) use ($container) {
// retrieve logger from $container here and log the error
$response->getBody()->rewind();
return $response->withStatus(500)
->withHeader('Content-Type', 'text/html')
->write("Oops, something's gone wrong!");
};
};
If you don’t want to repeat yourself, you can register the phpErrorHandler like this:
$container['phpErrorHandler'] = function ($container) {
return $container['errorHandler'];
};
###==============================
I modified the If you don’t want to repeat yourself section in 5 different ways (pasted below), of which Style 4 and 5 , is creating problem. All other works fine.
Is it due to the getter and setter mechanism, implementation behaviour of $container[‘key’] within Slim ?
If not, I need more dig on PHP Basics !!!
Please guide.
Thanks in advance
Susanth K
Style #1 ~~~~~~~~~~
$myErrorHandler = function ($container) {
//…
};
$container['phpErrorHandler'] = $myErrorHandler;
$container['errorHandler'] = $myErrorHandler;
// WORKS COOL :)
Style #2 ~~~~~~~~~~
$container['phpErrorHandler'] = $container['errorHandler'] = function ($container) {
//…
};
// WORKS COOL :)
Style #3 ~~~~~~~~~~
$container['errorHandler'] = $container['phpErrorHandler'] = function ($container) {
//…
};
// WORKS COOL :)
Style #4 ~~~~~~~~~~
$container['phpErrorHandler'] = function ($container) {
//…
};
$container['errorHandler'] = $container['phpErrorHandler'];
// NOT WORKING :(
// Warning: Missing argument 2 for {closure}()
// Warning: Missing argument 3 for {closure}()
Style #5 ~~~~~~~~~~
$container['errorHandler'] = function ($container) {
//…
};
$container['phpErrorHandler'] = $container['errorHandler'];
// NOT WORKING :(
// Warning: Missing argument 2 for {closure}()
// Warning: Missing argument 3 for {closure}()