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

Assertions can generate warnings #119

Open
BackEndTea opened this issue Aug 7, 2019 · 1 comment · May be fixed by #257
Open

Assertions can generate warnings #119

BackEndTea opened this issue Aug 7, 2019 · 1 comment · May be fixed by #257
Labels

Comments

@BackEndTea
Copy link
Collaborator

Some assertions call functions that may generate a warning if called with incorrect parameters, e.g. preg_match, strlen.

It would be better if they do not generate a warning when called, but either pass the assertion, or throw the exception.

This can be solved in one of two ways:

  • Silence errors using @ where possible
  • Assert the input is of the correct type, and throw an exception when it is not.

The issue with the second type is that it is a theoretical BC break. For example, the user may input an object that can be cast to a string, in which case most functions will do so, in which case it may pass the assertion.

Silencing the errors will however not save us from the TypeErrors that php 8.0 will start throwing: https://wiki.php.net/rfc/consistent_type_errors.

There is also the current issue of all the count related assertions, which do not check if the passed value is countable. So before php 7.2 everything is fine, but after that an warning is generated.

Personally i'm fine with the theoretical BC break, as it isn't really intended behaviour, as it is dependent on the implementation.

@zerkms
Copy link
Contributor

zerkms commented May 30, 2020

The second path should not be a BC: if input was so wrong that it throws a php warning - then the assertion should have failed as well.

@patka-123 patka-123 linked a pull request Oct 22, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants