Skip to content

Commit 755ddc6

Browse files
Throw ValueError when 1 is provided to the second argument of log()
1 parent d8e014d commit 755ddc6

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ PHP 8.5 UPGRADE NOTES
142142
. Using a printf-family function with a formatter that did not specify the
143143
precision previously incorrectly reset the precision instead of treating
144144
it as a precision of 0. See GH-18897.
145+
. Passing 1 as the second argument to log() now throws a ValueError.
146+
Previously, it returned NaN.
145147

146148
========================================
147149
2. New Features

ext/standard/math.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,9 @@ PHP_FUNCTION(log)
667667
RETURN_DOUBLE(log10(num));
668668
}
669669

670-
if (base == 1.0) {
671-
RETURN_DOUBLE(ZEND_NAN);
672-
}
673-
674-
if (base <= 0.0) {
675-
zend_argument_value_error(2, "must be greater than 0");
676-
RETURN_THROWS();
670+
if (base <= 0.0 || base == 1.0) {
671+
zend_argument_value_error(2, "must not be 1 or less than or equal to 0");
672+
RETURN_THROWS();
677673
}
678674

679675
RETURN_DOUBLE(log(num) / log(base));

ext/standard/tests/math/log_error.phpt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ try {
99
} catch (ValueError $exception) {
1010
echo $exception->getMessage() . "\n";
1111
}
12+
13+
try {
14+
log(36, 1);
15+
} catch (ValueError $exception) {
16+
echo $exception->getMessage() . "\n";
17+
}
1218
?>
1319
--EXPECT--
14-
log(): Argument #2 ($base) must be greater than 0
20+
log(): Argument #2 ($base) must not be 1 or less than or equal to 0
21+
log(): Argument #2 ($base) must not be 1 or less than or equal to 0

0 commit comments

Comments
 (0)