-
Notifications
You must be signed in to change notification settings - Fork 736
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
PHP 8.4: trigger_error() updates #4063
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
if ($divisor == 0) { | ||
trigger_error("Cannot divide by zero", E_USER_ERROR); | ||
if (is_nan($divisor)) { | ||
trigger_error("Cannot divide by NAN", E_USER_WARNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message makes not much sense, given that E_USER_WARNING
would not abort, so the division will be carried out. Maybe:
trigger_error("Cannot divide by NAN", E_USER_WARNING); | |
trigger_error("Division by NAN", E_USER_WARNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, finding a good example is hard, because generally speaking there is no good reason to use trigger_error()
nowadays. Either use an Exception or use error_log()
or another logging facility. But PHP's internal error reporting mechanism which allows for side-effects is not a good idea.
That said, how about this:
$password = $_POST['password'] ?? '';
if ($password === '') {
trigger_error("Using an empty password is unsafe", E_USER_WARNING);
}
$hash = password_hash($password, PASSWORD_DEFAULT);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would require that the error is shown to the user, though.
if ($divisor == 0) { | ||
trigger_error("Cannot divide by zero", E_USER_ERROR); | ||
if (is_nan($divisor)) { | ||
trigger_error("Cannot divide by NAN", E_USER_WARNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, finding a good example is hard, because generally speaking there is no good reason to use trigger_error()
nowadays. Either use an Exception or use error_log()
or another logging facility. But PHP's internal error reporting mechanism which allows for side-effects is not a good idea.
That said, how about this:
$password = $_POST['password'] ?? '';
if ($password === '') {
trigger_error("Using an empty password is unsafe", E_USER_WARNING);
}
$hash = password_hash($password, PASSWORD_DEFAULT);
be8caa9
to
9b38b00
Compare
Turns out the return type is already correct.
I have no idea for a "good" example, I was going to go for something to use
E_USER_DEPRECATED
but realised the newDeprecated
attribute is better suited for this.Maybe @TimWolla has opinions on how to format it for a See Also section?