This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component
Fabien Potencier 98e86816ad feature #33155 [ErrorHandler] Added call() method utility to turns 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 | https://github.com/symfony/symfony/issues/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 https://github.com/symfony/symfony/issues/32936#issuecomment-518152681 and @vudaltsov for the idea.

Commits
-------

0faa855b5e Added ErrorHandler::call() method utility to turns any PHP warnings into `\ErrorException`
2019-08-18 10:09:38 +02:00
..
Asset Remove superfluous phpdoc tags 2019-08-14 13:59:53 +02:00
BrowserKit Merge branch '4.3' into 4.4 2019-08-13 08:48:26 +02:00
Cache Import return annotations from vendors 2019-08-14 15:27:41 +02:00
Config Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Console Merge branch '4.3' into 4.4 2019-08-16 08:37:15 +02:00
CssSelector Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Debug Import return annotations from vendors 2019-08-14 15:27:41 +02:00
DependencyInjection [DI] fix dumping lazy proxies 2019-08-15 11:38:48 +02:00
DomCrawler Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Dotenv Remove superfluous phpdoc tags 2019-08-14 13:59:53 +02:00
ErrorHandler feature #33155 [ErrorHandler] Added call() method utility to turns any PHP error into \ErrorException (yceruto) 2019-08-18 10:09:38 +02:00
ErrorRenderer Fix deprecation in 4.4 branche 2019-08-08 21:31:13 +02:00
EventDispatcher Merge branch '4.3' into 4.4 2019-08-10 22:49:34 +02:00
ExpressionLanguage Merge branch '4.3' into 4.4 2019-08-08 14:07:40 +02:00
Filesystem Merge branch '4.3' into 4.4 2019-08-13 08:48:26 +02:00
Finder Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Form Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
HttpClient Bump minimal requirements 2019-08-10 23:01:55 +02:00
HttpFoundation Merge branch '3.4' into 4.3 2019-08-14 14:26:46 +02:00
HttpKernel Import return annotations from vendors 2019-08-14 15:27:41 +02:00
Inflector Merge branch '4.3' into 4.4 2019-08-07 14:00:28 +02:00
Intl [Intl] Validate region preferred alpha code mapping 2019-08-15 15:06:57 +02:00
Ldap Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Lock trigger a deprecation not a notice 2019-08-15 09:51:39 +02:00
Mailer [Mailer] added a way to test the number of queued emails 2019-08-16 21:31:41 +02:00
Messenger Merge branch '4.3' into 4.4 2019-08-14 15:26:12 +02:00
Mime Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
OptionsResolver Merge branch '4.3' into 4.4 2019-08-08 14:07:40 +02:00
Process Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
PropertyAccess Merge branch '3.4' into 4.3 2019-08-14 14:26:46 +02:00
PropertyInfo Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Routing Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Security Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Serializer Merge branch '4.3' into 4.4 2019-08-16 08:37:15 +02:00
Stopwatch Merge branch '4.3' into 4.4 2019-08-07 14:00:28 +02:00
Templating Merge branch '4.3' into 4.4 2019-08-08 14:07:40 +02:00
Translation Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Validator Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
VarDumper Merge branch '4.3' into 4.4 2019-08-16 08:37:15 +02:00
VarExporter Merge branch '4.3' into 4.4 2019-08-08 22:52:24 +02:00
WebLink Import return annotations from vendors 2019-08-14 15:27:41 +02:00
Workflow Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00
Yaml Merge branch '4.3' into 4.4 2019-08-14 14:37:46 +02:00