Skip to content

Commit 5076507

Browse files
committed
Improve some ValueError messages
Closes GH-5340
1 parent 21cfa03 commit 5076507

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+274
-247
lines changed

ext/bz2/bz2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ PHP_FUNCTION(bzread)
317317
php_stream_from_zval(stream, bz);
318318

319319
if (len < 0) {
320-
zend_value_error("Length cannot be negative");
320+
zend_argument_value_error(2, "must be greater than or equal to 0");
321321
RETURN_THROWS();
322322
}
323323

@@ -345,7 +345,7 @@ PHP_FUNCTION(bzopen)
345345
}
346346

347347
if (mode_len != 1 || (mode[0] != 'r' && mode[0] != 'w')) {
348-
zend_value_error("'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode);
348+
zend_argument_value_error(2, "must be a valid mode. Only 'w' and 'r' are supported");
349349
RETURN_THROWS();
350350
}
351351

ext/bz2/tests/001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ var_dump(bzopen($fp, "r"));
3737

3838
?>
3939
--EXPECTF--
40-
'' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
40+
bzopen(): Argument #2 ($mode) must be a valid mode. Only 'w' and 'r' are supported
4141

4242
Warning: bzopen(): Filename cannot be empty in %s on line %d
4343
bool(false)
4444

4545
Warning: bzopen(): Filename cannot be empty in %s on line %d
4646
bool(false)
47-
'x' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
48-
'rw' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.
47+
bzopen(): Argument #2 ($mode) must be a valid mode. Only 'w' and 'r' are supported
48+
bzopen(): Argument #2 ($mode) must be a valid mode. Only 'w' and 'r' are supported
4949

5050
Warning: bzopen(no_such_file): Failed to open stream: No such file or directory in %s on line %d
5151
bool(false)

ext/bz2/tests/003-mb.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var_dump(bzread($fd, 100000));
2121
?>
2222
--EXPECT--
2323
string(0) ""
24-
Length cannot be negative
24+
bzread(): Argument #2 ($length) must be greater than or equal to 0
2525
string(1) "R"
2626
string(2) "is"
2727
string(251) "ing up from the heart of the desert

ext/bz2/tests/003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var_dump(bzread($fd, 100000));
2121
?>
2222
--EXPECT--
2323
string(0) ""
24-
Length cannot be negative
24+
bzread(): Argument #2 ($length) must be greater than or equal to 0
2525
string(1) "R"
2626
string(2) "is"
2727
string(251) "ing up from the heart of the desert

ext/calendar/cal_unix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ PHP_FUNCTION(unixtojd)
3535
if (!ts) {
3636
ts = time(NULL);
3737
} else if (ts < 0) {
38-
zend_value_error("Timestamp must not be negative");
38+
zend_argument_value_error(1, "must be greater than or equal to 0");
3939
RETURN_THROWS();
4040
}
4141

ext/calendar/calendar.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ PHP_FUNCTION(cal_info)
194194

195195

196196
if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
197-
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
197+
zend_argument_value_error(1, "must be a valid calendar ID");
198198
RETURN_THROWS();
199199
}
200200

@@ -216,7 +216,7 @@ PHP_FUNCTION(cal_days_in_month)
216216
}
217217

218218
if (cal < 0 || cal >= CAL_NUM_CALS) {
219-
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
219+
zend_argument_value_error(1, "must be a valid calendar ID");
220220
RETURN_THROWS();
221221
}
222222

@@ -262,7 +262,7 @@ PHP_FUNCTION(cal_to_jd)
262262
}
263263

264264
if (cal < 0 || cal >= CAL_NUM_CALS) {
265-
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
265+
zend_argument_value_error(1, "must be a valid calendar ID");
266266
RETURN_THROWS();
267267
}
268268

@@ -283,7 +283,7 @@ PHP_FUNCTION(cal_from_jd)
283283
}
284284

285285
if (cal < 0 || cal >= CAL_NUM_CALS) {
286-
zend_value_error("Invalid calendar ID: " ZEND_LONG_FMT, cal);
286+
zend_argument_value_error(2, "must be a valid calendar ID");
287287
RETURN_THROWS();
288288
}
289289
calendar = &cal_conversion_table[cal];

ext/calendar/easter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, zend_long gm)
4949
}
5050

5151
if (gm && (year<1970 || year>2037)) { /* out of range for timestamps */
52-
zend_value_error("This function is only valid for years between 1970 and 2037 inclusive");
52+
zend_argument_value_error(1, "must be between 1970 and 2037 (inclusive)");
5353
RETURN_THROWS();
5454
}
5555

ext/calendar/tests/cal_days_in_month_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ try{
1818
}
1919
?>
2020
--EXPECT--
21-
Invalid calendar ID: -1
21+
cal_days_in_month(): Argument #1 ($calendar) must be a valid calendar ID
2222
Invalid date

ext/calendar/tests/cal_from_jd_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313
}
1414
?>
1515
--EXPECT--
16-
Invalid calendar ID: -1
16+
cal_from_jd(): Argument #2 ($calendar) must be a valid calendar ID

ext/calendar/tests/cal_info.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,4 @@ Array
216216
[calname] => Julian
217217
[calsymbol] => CAL_JULIAN
218218
)
219-
Invalid calendar ID: 99999
219+
cal_info(): Argument #1 ($calendar) must be a valid calendar ID

ext/calendar/tests/cal_to_jd_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ try {
1313
}
1414
?>
1515
--EXPECT--
16-
Invalid calendar ID: -1
16+
cal_to_jd(): Argument #1 ($calendar) must be a valid calendar ID

ext/calendar/tests/easter_date.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ try {
2222
2000-04-23
2323
2001-04-15
2424
2002-03-31
25-
This function is only valid for years between 1970 and 2037 inclusive
25+
easter_date(): Argument #1 ($year) must be between 1970 and 2037 (inclusive)

ext/calendar/tests/unixtojd_error1.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var_dump(unixtojd(null)) . PHP_EOL;
2020
var_dump(unixtojd(time())) . PHP_EOL;
2121
?>
2222
--EXPECTF--
23-
Timestamp must not be negative
23+
unixtojd(): Argument #1 ($timestamp) must be greater than or equal to 0
2424
int(%d)
2525
int(%d)
2626
int(%d)

0 commit comments

Comments
 (0)