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

Add support for lazy messages #265

Open
theofidry opened this issue Feb 5, 2022 · 1 comment
Open

Add support for lazy messages #265

theofidry opened this issue Feb 5, 2022 · 1 comment

Comments

@theofidry
Copy link

theofidry commented Feb 5, 2022

On some occasions, in order to provide a helpful error message, more processing is required to provide a helpful message:

$message = $createMessage(...); // heavy stuff happening there

Assert::smth(..., $message);

Maybe it would be cool to have support for $message being string|():string instead of just string:

Assert::smth(..., $createMessage);

In some cases this may end up more verbose, but on the other hand it prevents the assertion from being expensive in case of non-failure (the happy path).

WDYT?

@gnutix
Copy link

gnutix commented Feb 27, 2023

Doing some profiling on our app, it often happens that sprintf() calls with complex processing (implode and such) are the culprit of bad performance. Worst than that, 99% of the time they are executed without any need to.

It's sad to have to use if (...) { throw new InvalidArgumentException(...); } instead of Assert just for that reason...
@BackEndTea What would be needed to make this issue fixed? Is there a particular blocker?

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

No branches or pull requests

2 participants