Skip to content

Commit c43179f

Browse files
committed
Promote base_convert "invalid base" errors to ValueError
1 parent 26327bc commit c43179f

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

ext/standard/math.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,12 +1098,12 @@ PHP_FUNCTION(base_convert)
10981098
}
10991099

11001100
if (frombase < 2 || frombase > 36) {
1101-
php_error_docref(NULL, E_WARNING, "Invalid `from base' (" ZEND_LONG_FMT ")", frombase);
1102-
RETURN_FALSE;
1101+
zend_value_error("Invalid `from base' (" ZEND_LONG_FMT ")", frombase);
1102+
return;
11031103
}
11041104
if (tobase < 2 || tobase > 36) {
1105-
php_error_docref(NULL, E_WARNING, "Invalid `to base' (" ZEND_LONG_FMT ")", tobase);
1106-
RETURN_FALSE;
1105+
zend_value_error("Invalid `to base' (" ZEND_LONG_FMT ")", tobase);
1106+
return;
11071107
}
11081108

11091109
_php_math_basetozval(Z_STR_P(number), (int)frombase, &temp);

ext/standard/tests/math/base_convert_error.phpt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ class classA
1414
{
1515
}
1616

17-
echo "Incorrect input\n";
18-
base_convert(1234, 1, 10);
19-
base_convert(1234, 10, 37);
17+
try {
18+
base_convert(1234, 1, 10);
19+
} catch (ValueError $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
try {
23+
base_convert(1234, 10, 37);
24+
} catch (ValueError $e) {
25+
echo $e->getMessage(), "\n";
26+
}
2027

2128
try {
2229
base_convert(new classA(), 8, 10);
@@ -25,11 +32,8 @@ try {
2532
}
2633

2734
?>
28-
--EXPECTF--
35+
--EXPECT--
2936
*** Testing base_convert() : error conditions ***
30-
Incorrect input
31-
32-
Warning: base_convert(): Invalid `from base' (1) in %s on line %d
33-
34-
Warning: base_convert(): Invalid `to base' (37) in %s on line %d
37+
Invalid `from base' (1)
38+
Invalid `to base' (37)
3539
Object of class classA could not be converted to string

0 commit comments

Comments
 (0)