Skip to content

Commit 37556ec

Browse files
Merge branch '5.0' into 5.1
* 5.0: Handle fetch mode deprecation of DBAL 2.11. Fixed handling of CSRF logout error [WebProfilerBundle] changed label of memory usage in time panel (Mb into MiB) [DotEnv][WebLink][Templating][ErrorHandler] Updated README with minimal example
2 parents 5515d56 + baf1f94 commit 37556ec

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,35 @@ ErrorHandler Component
33

44
The ErrorHandler component provides tools to manage errors and ease debugging PHP code.
55

6+
Getting Started
7+
---------------
8+
9+
```
10+
$ composer require symfony/error-handler
11+
```
12+
13+
```php
14+
use Symfony\Component\ErrorHandler\Debug;
15+
use Symfony\Component\ErrorHandler\ErrorHandler;
16+
use Symfony\Component\ErrorHandler\DebugClassLoader;
17+
18+
Debug::enable();
19+
20+
// or enable only one feature
21+
//ErrorHandler::register();
22+
//DebugClassLoader::enable();
23+
24+
$data = ErrorHandler::call(static function () use ($filename, $datetimeFormat) {
25+
// if any code executed inside this anonymous function fails, a PHP exception
26+
// will be thrown, even if the code uses the '@' PHP silence operator
27+
$data = json_decode(file_get_contents($filename), true);
28+
$data['read_at'] = date($datetimeFormat);
29+
file_put_contents($filename, json_encode($data));
30+
31+
return $data;
32+
});
33+
```
34+
635
Resources
736
---------
837

0 commit comments

Comments
 (0)