Closed petitchevalroux closed 9 years ago
Dont think this is Slim related. Try if you have the same behaviour outside of Slim. Also take a look at error_reporting
@JoeBengalen Thank you for your quick answer. Outside of Slim, updating error_reporting does not modify script behaviour E_ERROR => halt script E_WARNING => does not halt the script and that's it.
I think this may be due to Slim::handleErrors
Ohw you using slim v2. I've never used that version myself so I cannot really help you with that. But looking at the code Slim should respect the error reporting level: https://github.com/slimphp/Slim/blob/2.x/Slim/Slim.php#L1408
Totally agree with you, but error_reporting should just interfere with error displaying and logging, and imho not changing script behavior.
Replace Slim's handleErrors
with your own one.
@akrabat can you explain me how to do that ? btw the problem occured with E_USER_NOTICE too if it's is in error_reporting.
http://docs.slimframework.com/errors/500/
$app->error(function (\Exception $e) use ($app) {
// do something here
});
Overloading errorHandler does not change anything. handleErrors trigger ErrorException stopping the call process
handlerErrors()
checks the error reporting level before throwing the exception. Try setting the error reporting level to 0 and try again. The exception should not be thrown.
error_reporting(0);
Note. You should not leave error reporting at 0, but just to test it for now.
Ah yeah. Sorry.
What you need to do is write your own middleware that resets the error handler:
<?php
require '../vendor/autoload.php';
class ErrorHandlerMiddleware extends \Slim\Middleware
{
public function call()
{
set_error_handler(null);
$this->next->call();
}
}
$app = new \Slim\Slim();
$app->add(new ErrorHandlerMiddleware);
$app->get('/', function () use ($app) {
trigger_error('E_USER_WARNING', E_USER_WARNING);
echo "<p>Here</p>";
});
$app->run();
Or, extend the Slim class and override handleErrors
:)
@JoeBengalen this what I said before, removing E_WARNING from error_reporting does the job ;) @akrabat I was reading the PrettyExceptions middleware in order to write my own error middleware ;)
Despite i fixed this for my usage, don't you think it's a major issue ?
Slim 2 is no longer under active development and is only accepting security fixes.
Slim 3 doesn't have this "feature" :)
ok and is slim 3 ready for "end user" ?
We're at beta 2. Expecting RC1 towards the end of next week.
Nice, i will give it a try.
BTW, thank you for your help ;)
You're welcome :)
According to http://php.net/manual/en/errorfunc.constants.php E_WARNING should not halt script execution
To reproduce : $app->get('/hello/:name', function ($name) { trigger_error('E_USER_WARNING', E_USER_WARNING); echo "Hello, $name"; });
=> I get a 500 error
Removing E_WARNING from error_reporting disable this behavior but for me reporting setting's should not interfere with script execution.