Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[ErrorHandler] Added call() method utility to turns any PHP error into \ErrorException#33155
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
vudaltsov commentedAug 14, 2019
Nice! Thanx for working on this :) |
1619843 toaf717e6CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
…nto `\ErrorException`
yceruto commentedAug 14, 2019
@ro0NL comments addressed, thanks! |
fabpot commentedAug 18, 2019
Thank you@yceruto. |
…y PHP error into \ErrorException (yceruto)This PR was merged into the 4.4 branch.Discussion----------[ErrorHandler] Added call() method utility to turns any PHP error into \ErrorException| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#32936| License | MIT| Doc PR | symfony/symfony-docs#...**Issue**There is no easy way to catch PHP warnings, though some progress has been made in this area for PHP 8.0 (https://wiki.php.net/rfc/consistent_type_errors).**Before**```php$file = file_get_contents('unknown.txt');// PHP Warning: file_get_contents(unknown.txt): failed to open stream: No such file or directory// workaround:$file = @file_get_contents('unknown.txt');if (false === $file) { $e = error_get_last(); throw new \ErrorException($e['message'], 0, $e['type'], $e['file'], $e['line']);}```**After**```php$file = ErrorHandler::call('file_get_contents', 'unknown.txt');// or$file = ErrorHandler::call(static function () { return file_get_contents('unknown.txt');});// or (PHP 7.4)$file = ErrorHandler::call(fn () => file_get_contents('unknown.txt'));```All credits to@nicolas-grekas#32936 (comment) and@vudaltsov for the idea.Commits-------0faa855 Added ErrorHandler::call() method utility to turns any PHP warnings into `\ErrorException`
…urns any PHP error into \ErrorException (yceruto)This PR was merged into the 4.4 branch.Discussion----------[ErrorHandler] Added call() method utility to turns any PHP error into \ErrorException| Q | A| ------------- | ---| Branch? | 4.4| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |symfony#32936| License | MIT| Doc PR | symfony/symfony-docs#...**Issue**There is no easy way to catch PHP warnings, though some progress has been made in this area for PHP 8.0 (https://wiki.php.net/rfc/consistent_type_errors).**Before**```php$file = file_get_contents('unknown.txt');// PHP Warning: file_get_contents(unknown.txt): failed to open stream: No such file or directory// workaround:$file = @file_get_contents('unknown.txt');if (false === $file) { $e = error_get_last(); throw new \ErrorException($e['message'], 0, $e['type'], $e['file'], $e['line']);}```**After**```php$file = ErrorHandler::call('file_get_contents', 'unknown.txt');// or$file = ErrorHandler::call(static function () { return file_get_contents('unknown.txt');});// or (PHP 7.4)$file = ErrorHandler::call(fn () => file_get_contents('unknown.txt'));```All credits to@nicolas-grekassymfony#32936 (comment) and@vudaltsov for the idea.Commits-------0faa855 Added ErrorHandler::call() method utility to turns any PHP warnings into `\ErrorException`
Issue
There is no easy way to catch PHP warnings, though some progress has been made in this area for PHP 8.0 (https://wiki.php.net/rfc/consistent_type_errors).
Before
After
All credits to@nicolas-grekas#32936 (comment) and@vudaltsov for the idea.