Skip to content

Commit 964eff5

Browse files
Throw ValueError when 1 is provided to the second argument of log()
1 parent dc79609 commit 964eff5

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ PHP NEWS
77
with a given skeleton, locale, collapse type and identity fallback.
88
(BogdanUngureanu)
99

10+
- Standard:
11+
. Passing 1 or negative base to log() now throws a ValueError.
12+
(alexandre-daubois)
13+
1014
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

ext/standard/math.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,8 @@ 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");
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");
676672
RETURN_THROWS();
677673
}
678674

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)