Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:4.4fromyceruto:error_handler_call
Aug 18, 2019

Conversation

@yceruto
Copy link
Member

QA
Branch?4.4
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#32936
LicenseMIT
Doc PRsymfony/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

$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();thrownew \ErrorException($e['message'],0,$e['type'],$e['file'],$e['line']);}

After

$file = ErrorHandler::call('file_get_contents','unknown.txt');// or$file = ErrorHandler::call(staticfunction () {returnfile_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.

@vudaltsov
Copy link
Contributor

Nice! Thanx for working on this :)

@ycerutoycerutoforce-pushed theerror_handler_call branch 3 times, most recently from1619843 toaf717e6CompareAugust 14, 2019 12:10
@ycerutoyceruto changed the title[ErrorHandler] Added call() method utility to turns any PHP warnings into \ErrorException[ErrorHandler] Added call() method utility to turns any PHP error into \ErrorExceptionAug 14, 2019
@yceruto
Copy link
MemberAuthor

@ro0NL comments addressed, thanks!

@fabpot
Copy link
Member

Thank you@yceruto.

fabpot added a commit that referenced this pull requestAug 18, 2019
…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`
@fabpotfabpot merged commit0faa855 intosymfony:4.4Aug 18, 2019
@ycerutoyceruto deleted the error_handler_call branchAugust 18, 2019 13:15
@nicolas-grekasnicolas-grekas modified the milestones:next,4.4Oct 27, 2019
This was referencedNov 12, 2019
PhilETaylor pushed a commit to PhilETaylor/symfony that referenced this pull requestSep 6, 2023
…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`
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+4 more reviewers

@ro0NLro0NLro0NL left review comments

@vudaltsovvudaltsovvudaltsov left review comments

@fancywebfancywebfancyweb left review comments

@ismail1432ismail1432ismail1432 left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.4

Development

Successfully merging this pull request may close these issues.

8 participants

@yceruto@vudaltsov@fabpot@nicolas-grekas@ro0NL@fancyweb@ismail1432@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp