Skip to content

Commit 441b326

Browse files
committed
Promote warning to exception in log() function
1 parent e208d23 commit 441b326

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static const func_info_t func_infos[] = {
291291
F0("log1p", MAY_BE_DOUBLE),
292292
F1("pow", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
293293
F0("exp", MAY_BE_DOUBLE),
294-
F0("log", MAY_BE_FALSE | MAY_BE_DOUBLE),
294+
F0("log", MAY_BE_DOUBLE),
295295
F0("log10", MAY_BE_DOUBLE),
296296
F0("sqrt", MAY_BE_DOUBLE),
297297
F0("hypot", MAY_BE_DOUBLE),

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ function pow($base, $exp) {}
911911

912912
function exp(float $number): float {}
913913

914-
function log(float $number, float $base = M_E): float|false {}
914+
function log(float $number, float $base = M_E): float {}
915915

916916
function log10(float $number): float {}
917917

ext/standard/basic_functions_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,7 +1386,7 @@ ZEND_END_ARG_INFO()
13861386

13871387
#define arginfo_exp arginfo_ceil
13881388

1389-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_log, 0, 1, MAY_BE_DOUBLE|MAY_BE_FALSE)
1389+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_log, 0, 1, IS_DOUBLE, 0)
13901390
ZEND_ARG_TYPE_INFO(0, number, IS_DOUBLE, 0)
13911391
ZEND_ARG_TYPE_INFO(0, base, IS_DOUBLE, 0)
13921392
ZEND_END_ARG_INFO()

ext/standard/math.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ PHP_FUNCTION(log1p)
679679
}
680680
/* }}} */
681681

682-
/* {{{ proto float|false log(float number, [float base])
682+
/* {{{ proto float log(float number, [float base])
683683
Returns the natural logarithm of the number, or the base log if base is specified */
684684
PHP_FUNCTION(log)
685685
{
@@ -710,8 +710,8 @@ PHP_FUNCTION(log)
710710
}
711711

712712
if (base <= 0.0) {
713-
php_error_docref(NULL, E_WARNING, "base must be greater than 0");
714-
RETURN_FALSE;
713+
zend_value_error("Base must be greater than 0");
714+
return;
715715
}
716716

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

ext/standard/tests/math/log_error.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Test log() - wrong params test log()
44
precision=14
55
--FILE--
66
<?php
7-
log(36, -4);
7+
try {
8+
log(36, -4);
9+
} catch (ValueError $exception) {
10+
echo $exception->getMessage() . "\n";
11+
}
812
?>
9-
--EXPECTF--
10-
Warning: log(): base must be greater than 0 in %s on line %d
13+
--EXPECT--
14+
Base must be greater than 0

0 commit comments

Comments
 (0)