Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ PHP NEWS
with a given skeleton, locale, collapse type and identity fallback.
(BogdanUngureanu)

- Standard:
. Passing 1 or negative base to log() now throws a ValueError.
(alexandre-daubois)

<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
8 changes: 2 additions & 6 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,12 +667,8 @@ PHP_FUNCTION(log)
RETURN_DOUBLE(log10(num));
}

if (base == 1.0) {
RETURN_DOUBLE(ZEND_NAN);
}

if (base <= 0.0) {
zend_argument_value_error(2, "must be greater than 0");
if (base <= 0.0 || base == 1.0) {
zend_argument_value_error(2, "must not be 1 or less than or equal to 0");
Comment on lines +670 to +671
Copy link
Member

Choose a reason for hiding this comment

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

I would split it to two independent messages if we decide to do it.

RETURN_THROWS();
}

Expand Down
9 changes: 8 additions & 1 deletion ext/standard/tests/math/log_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ try {
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

try {
log(36, 1);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECT--
log(): Argument #2 ($base) must be greater than 0
log(): Argument #2 ($base) must not be 1 or less than or equal to 0
log(): Argument #2 ($base) must not be 1 or less than or equal to 0
Loading