Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to cath user_error() and use set_error_handler() inside controller?
  • I am using phpseclib SSH2 implementation, but the library doesn't throw errors but instead uses user_error (http://php.net/manual/en/function.user-error.php) and set_error_handler for handling errors http://php.net/manual/en/function.set-error-handler.php...

    How do I catch this kind of error inside my controller code?
  • You can't.

    The framework itself converts PHP errors to Exceptions which you can catch, but that doesn't work if PHPSecLib uses it's own error handler...
  • How do I tell if its using its own error handler or not and how to route it to Fuel?
  • A quick scan of the code shows that PHPSecLib doesn't come with it's own error handlers, to the user errors that are generated will be caught by the frameworks error handler, which will convert it to an Exception.

    Just noticed that the Error class had a bug that made user-errors not catchable. I've fixed that in 1.6/develop, so if you're on 1.5.x, you might want to backport that class to make it work for you.

    It allows you to do

    try
    {
        user_error('this is a user notice', E_USER_NOTICE);
    }
    catch (\PhpErrorException)
    {
        echo 'got you!';
    }

    In your case, the SSH calls should be inside the try block...
  • Ok I will try. Thanks for helping out!
  • I have tried this on 1.5 and it was catching it fine?
  • Ok. So problem solved then?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion