Skip to content

Commit 04deb53

Browse files
committed
Promote warning to exception in log() function
1 parent 616ec2d commit 04deb53

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

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
@@ -596,7 +596,7 @@ PHP_FUNCTION(log1p)
596596
}
597597
/* }}} */
598598

599-
/* {{{ proto float|false log(float number, [float base])
599+
/* {{{ proto float log(float number, [float base])
600600
Returns the natural logarithm of the number, or the base log if base is specified */
601601
PHP_FUNCTION(log)
602602
{
@@ -625,8 +625,8 @@ PHP_FUNCTION(log)
625625
}
626626

627627
if (base <= 0.0) {
628-
php_error_docref(NULL, E_WARNING, "base must be greater than 0");
629-
RETURN_FALSE;
628+
zend_value_error("Base must be greater than 0");
629+
return;
630630
}
631631

632632
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)