Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add default parameter to throw_if / throw_unless (attempt 2) #35890

Merged
merged 1 commit into from Jan 14, 2021
Merged

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Jan 14, 2021

This is a follow-up on #35888

You can now pass throw_if and throw_unless a message as the second parameter, similar to the report function (which was changed in #35803):

// Currently:
throw_if($sometingIsWrong, new RuntimeException('something wrong with user '.$user->id));

// With this PR:
throw_if($sometingIsWrong, 'something wrong with user '.$user->id);

If the message passed is an existing class, that will be used as the exception instead:

throw_if($somethingIsWrong, LogicException::class);

And the newly added default parameter allows you to also do this, if you're not interested in a custom message:

throw_if($somethingIsWrong);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants