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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ PHP NEWS
. Add enum SortDirection. (timwolla)
. pathinfo() raises a ValueError with an invalid $flags argument.
(David Carlier)
. Passing 1 or negative base to log() now throws a ValueError.
(alexandre-daubois)

- Streams:
. Added so_keepalive, tcp_keepidle, tcp_keepintvl and tcp_keepcnt stream
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ PHP 8.6 UPGRADE NOTES
constants).

- Standard:
. log() now raises a ValueError when the base argument is 1 or less
than or equal to 0. Previously, base 1 silently returned NAN.
. pathinfo() now raises a ValueError when an invalid $flag argument
value is passed.

Expand Down
8 changes: 2 additions & 6 deletions ext/standard/math.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,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");
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