Skip to content

Throw ValueError when 1 is provided to the second argument of log() #19370

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexandre-daubois
Copy link
Contributor

This helps with early error detection and explicit intent, instead of having a potential NaN propagating.

Comment on lines 670 to 675
if (base == 1.0) {
RETURN_DOUBLE(ZEND_NAN);
zend_argument_value_error(2, "must not be 1");
RETURN_THROWS();
}

if (base <= 0.0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to unify both conditions and messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that values in ]0;1[ work, I'm not sure. I like having an accurate error message, however I'm not against having "must not be 1 or less than 0" if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a combined message as you suggested is better.
But people might think that going straight to a ValueError is too harsh in which case we would need a warning... but this feels like it should be fine.

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

Successfully merging this pull request may close these issues.

2 participants