Skip to content

Commit 4def16d

Browse files
committed
Promote a few remaining errors in ext/standard
1 parent 3861cb8 commit 4def16d

Some content is hidden

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

64 files changed

+1098
-1001
lines changed

Zend/tests/bug41026.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ echo "Done\n";
2323
--EXPECT--
2424
Done
2525

26-
Warning: (Registered shutdown functions) Unable to call self::on_shutdown() - function does not exist in Unknown on line 0
26+
Fatal error: Registered shutdown function self::on_shutdown() cannot be called, function does not exist in Unknown on line 0

ext/mbstring/mbstring.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,8 @@ PHP_FUNCTION(mb_strcut)
22332233
}
22342234

22352235
if (from > string.len) {
2236-
// TODO Out of bounds ValueError
2237-
RETURN_FALSE;
2236+
zend_argument_value_error(3, "must be contained in argument #1 ($str)");
2237+
RETURN_THROWS();
22382238
}
22392239

22402240
ret = mbfl_strcut(&string, &result, from, len);
@@ -3512,6 +3512,9 @@ PHP_FUNCTION(mb_send_mail)
35123512
zend_string_release_ex(tmp_headers, 0);
35133513
} else if (headers_ht) {
35143514
str_headers = php_mail_build_headers(headers_ht);
3515+
if (!str_headers) {
3516+
RETURN_THROWS();
3517+
}
35153518
}
35163519

35173520
if (extra_cmd) {

ext/mbstring/mbstring.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function mb_substr_count(string $haystack, string $needle, ?string $encoding = n
4545

4646
function mb_substr(string $str, int $start, ?int $length = null, ?string $encoding = null): string {}
4747

48-
function mb_strcut(string $str, int $start, ?int $length = null, ?string $encoding = null): string|false {}
48+
function mb_strcut(string $str, int $start, ?int $length = null, ?string $encoding = null): string {}
4949

5050
function mb_strwidth(string $str, ?string $encoding = null): int {}
5151

ext/mbstring/tests/bug49354.phpt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ var_dump(mb_strcut($crap, 1, 100, 'UTF-8'));
1010
var_dump(mb_strcut($crap, 2, 100, 'UTF-8'));
1111
var_dump(mb_strcut($crap, 3, 100, 'UTF-8'));
1212
var_dump(mb_strcut($crap, 12, 100, 'UTF-8'));
13-
var_dump(mb_strcut($crap, 13, 100, 'UTF-8'));
13+
14+
try {
15+
mb_strcut($crap, 13, 100, 'UTF-8');
16+
} catch (ValueError $exception) {
17+
echo $exception->getMessage() . "\n";
18+
}
19+
1420
?>
1521
--EXPECT--
1622
string(12) "AåBäCöDü"
1723
string(11) "åBäCöDü"
1824
string(11) "åBäCöDü"
1925
string(9) "BäCöDü"
2026
string(0) ""
21-
bool(false)
27+
mb_strcut(): Argument #3 ($length) must be contained in argument #1 ($str)

ext/mbstring/tests/mb_strcut.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ print MBStringChars(mb_strcut($euc_jp, 6, 5,'EUC-JP'), 'EUC-JP') . "\n";
2828
print MBStringChars(mb_strcut($euc_jp, 5, 5,'EUC-JP'), 'EUC-JP') . "\n";
2929
print MBStringChars(mb_strcut($euc_jp, 0, 100,'EUC-JP'), 'EUC-JP') . "\n";
3030

31-
$str = mb_strcut($euc_jp, 100, 10,'EUC-JP');
32-
($str === false) ? print "OK\n" : print "No good\n";
31+
try {
32+
mb_strcut($euc_jp, 100, 10,'EUC-JP');
33+
} catch (ValueError $exception) {
34+
echo $exception->getMessage() . "\n";
35+
}
3336

3437
$str = mb_strcut($euc_jp, -100, 10,'EUC-JP');
3538
($str !== "") ? print "OK\n" : print "No good\n";
@@ -60,7 +63,7 @@ print MBStringChars(mb_strcut($utf16le, 1, 4, 'UTF-16LE'), 'UTF-16LE') . "\n";
6063
[a4ce cab8]
6164
[a4b3 a4ce]
6265
[30 31 32 33 a4b3 a4ce cab8 bbfa cef3 a4cf c6fc cbdc b8ec a4c7 a4b9 a1a3 45 55 43 2d 4a 50 a4f2 bbc8 a4c3 a4c6 a4a4 a4de a4b9 a1a3 c6fc cbdc b8ec a4cf cccc c5dd bdad a4a4 a1a3]
63-
OK
66+
mb_strcut(): Argument #3 ($length) must be contained in argument #1 ($str)
6467
OK
6568
== UTF-8 ==
6669
[]

ext/sodium/libsodium.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3067,7 +3067,7 @@ PHP_FUNCTION(sodium_unpad)
30673067
RETURN_THROWS();
30683068
}
30693069
if (padded_len < blocksize) {
3070-
zend_argument_error(sodium_exception_ce, 1, "must not be shorter than the block size");
3070+
zend_argument_error(sodium_exception_ce, 1, "must be at least as long as the block size");
30713071
RETURN_THROWS();
30723072
}
30733073

ext/standard/array.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -965,22 +965,6 @@ static int php_array_user_compare(Bucket *a, Bucket *b) /* {{{ */
965965
}
966966
/* }}} */
967967

968-
/* check if comparison function is valid */
969-
#define PHP_ARRAY_CMP_FUNC_CHECK(func_name) \
970-
if (!zend_is_callable(*func_name, 0, NULL)) { \
971-
php_error_docref(NULL, E_WARNING, "Invalid comparison function"); \
972-
BG(user_compare_fci) = old_user_compare_fci; \
973-
BG(user_compare_fci_cache) = old_user_compare_fci_cache; \
974-
RETURN_FALSE; \
975-
} \
976-
977-
/* Clear FCI cache otherwise : for example the same or other array with
978-
* (partly) the same key values has been sorted with uasort() or
979-
* other sorting function the comparison is cached, however the name
980-
* of the function for comparison is not respected. see bug #28739 AND #33295
981-
*
982-
* Following defines will assist in backup / restore values. */
983-
984968
#define PHP_ARRAY_CMP_FUNC_VARS \
985969
zend_fcall_info old_user_compare_fci; \
986970
zend_fcall_info_cache old_user_compare_fci_cache \
@@ -2570,7 +2554,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
25702554
zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
25712555
}
25722556
} else {
2573-
php_error_docref(NULL, E_NOTICE, "Undefined variable $%s", ZSTR_VAL(Z_STR_P(entry)));
2557+
php_error_docref(NULL, E_WARNING, "Undefined variable $%s", ZSTR_VAL(Z_STR_P(entry)));
25742558
}
25752559
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
25762560
if (Z_REFCOUNTED_P(entry)) {

ext/standard/basic_functions.c

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,8 @@ PHP_FUNCTION(time_sleep_until)
13101310
target_ns = (uint64_t) (target_secs * ns_per_sec);
13111311
current_ns = ((uint64_t) tm.tv_sec) * ns_per_sec + ((uint64_t) tm.tv_usec) * 1000;
13121312
if (target_ns < current_ns) {
1313-
php_error_docref(NULL, E_WARNING, "Sleep until to time is less than current time");
1314-
RETURN_FALSE;
1313+
zend_argument_value_error(1, "must be a timestamp greater than or equal to the current time");
1314+
RETURN_THROWS();
13151315
}
13161316

13171317
diff_ns = target_ns - current_ns;
@@ -1468,9 +1468,8 @@ PHPAPI int _php_error_log_ex(int opt_err, const char *message, size_t message_le
14681468
break;
14691469

14701470
case 2: /*send to an address */
1471-
php_error_docref(NULL, E_WARNING, "TCP/IP option not available!");
1471+
zend_value_error("TCP/IP option is not available for error logging");
14721472
return FAILURE;
1473-
break;
14741473

14751474
case 3: /*save to a file */
14761475
stream = php_stream_open_wrapper(opt, "a", IGNORE_URL_WIN | REPORT_ERRORS, NULL);
@@ -1684,10 +1683,9 @@ static int user_shutdown_function_call(zval *zv) /* {{{ */
16841683
zval retval;
16851684

16861685
if (!zend_is_callable(&shutdown_function_entry->arguments[0], 0, NULL)) {
1687-
zend_string *function_name
1688-
= zend_get_callable_name(&shutdown_function_entry->arguments[0]);
1689-
php_error(E_WARNING, "(Registered shutdown functions) Unable to call %s() - function does not exist", ZSTR_VAL(function_name));
1690-
zend_string_release_ex(function_name, 0);
1686+
zend_string *function_name = zend_get_callable_name(&shutdown_function_entry->arguments[0]);
1687+
zend_throw_error(NULL, "Registered shutdown function %s() cannot be called, function does not exist", ZSTR_VAL(function_name));
1688+
zend_string_release(function_name);
16911689
return 0;
16921690
}
16931691

@@ -1719,21 +1717,10 @@ static void user_tick_function_call(user_tick_function_entry *tick_fe) /* {{{ */
17191717
tick_fe->arguments + 1
17201718
) == SUCCESS) {
17211719
zval_ptr_dtor(&retval);
1722-
17231720
} else {
1724-
zval *obj, *method;
1725-
1726-
if (Z_TYPE_P(function) == IS_STRING) {
1727-
php_error_docref(NULL, E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_P(function));
1728-
} else if ( Z_TYPE_P(function) == IS_ARRAY
1729-
&& (obj = zend_hash_index_find(Z_ARRVAL_P(function), 0)) != NULL
1730-
&& (method = zend_hash_index_find(Z_ARRVAL_P(function), 1)) != NULL
1731-
&& Z_TYPE_P(obj) == IS_OBJECT
1732-
&& Z_TYPE_P(method) == IS_STRING) {
1733-
php_error_docref(NULL, E_WARNING, "Unable to call %s::%s() - function does not exist", ZSTR_VAL(Z_OBJCE_P(obj)->name), Z_STRVAL_P(method));
1734-
} else {
1735-
php_error_docref(NULL, E_WARNING, "Unable to call tick function");
1736-
}
1721+
zend_string *function_name = zend_get_callable_name(function);
1722+
zend_throw_error(NULL, "Registered tick function %s() cannot be called, function does not exist", ZSTR_VAL(function_name));
1723+
zend_string_release(function_name);
17371724
}
17381725

17391726
tick_fe->calling = 0;
@@ -1764,7 +1751,7 @@ static int user_tick_function_compare(user_tick_function_entry * tick_fe1, user_
17641751
}
17651752

17661753
if (ret && tick_fe1->calling) {
1767-
php_error_docref(NULL, E_WARNING, "Unable to delete tick function executed at the moment");
1754+
zend_throw_error(NULL, "Registered tick function cannot be unregistered while it is being executed");
17681755
return 0;
17691756
}
17701757
return ret;
@@ -1818,23 +1805,22 @@ PHP_FUNCTION(register_shutdown_function)
18181805

18191806
/* Prevent entering of anything but valid callback (syntax check only!) */
18201807
if (!zend_is_callable(&shutdown_function_entry.arguments[0], 0, NULL)) {
1821-
zend_string *callback_name
1822-
= zend_get_callable_name(&shutdown_function_entry.arguments[0]);
1823-
php_error_docref(NULL, E_WARNING, "Invalid shutdown callback '%s' passed", ZSTR_VAL(callback_name));
1808+
zend_string *callback_name = zend_get_callable_name(&shutdown_function_entry.arguments[0]);
1809+
zend_argument_type_error(1, "must be a valid callback, function \"%s\" not found or invalid function name", ZSTR_VAL(callback_name));
18241810
efree(shutdown_function_entry.arguments);
1825-
zend_string_release_ex(callback_name, 0);
1826-
RETVAL_FALSE;
1827-
} else {
1828-
if (!BG(user_shutdown_function_names)) {
1829-
ALLOC_HASHTABLE(BG(user_shutdown_function_names));
1830-
zend_hash_init(BG(user_shutdown_function_names), 0, NULL, user_shutdown_function_dtor, 0);
1831-
}
1811+
zend_string_release(callback_name);
1812+
RETURN_THROWS();
1813+
}
18321814

1833-
for (i = 0; i < shutdown_function_entry.arg_count; i++) {
1834-
Z_TRY_ADDREF(shutdown_function_entry.arguments[i]);
1835-
}
1836-
zend_hash_next_index_insert_mem(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry));
1815+
if (!BG(user_shutdown_function_names)) {
1816+
ALLOC_HASHTABLE(BG(user_shutdown_function_names));
1817+
zend_hash_init(BG(user_shutdown_function_names), 0, NULL, user_shutdown_function_dtor, 0);
1818+
}
1819+
1820+
for (i = 0; i < shutdown_function_entry.arg_count; i++) {
1821+
Z_TRY_ADDREF(shutdown_function_entry.arguments[i]);
18371822
}
1823+
zend_hash_next_index_insert_mem(BG(user_shutdown_function_names), &shutdown_function_entry, sizeof(php_shutdown_function_entry));
18381824
}
18391825
/* }}} */
18401826

@@ -2057,7 +2043,7 @@ PHP_FUNCTION(ini_get_all)
20572043

20582044
if (extname) {
20592045
if ((module = zend_hash_str_find_ptr(&module_registry, extname, extname_len)) == NULL) {
2060-
php_error_docref(NULL, E_WARNING, "Unable to find extension '%s'", extname);
2046+
php_error_docref(NULL, E_WARNING, "Extension \"%s\" cannot be found", extname);
20612047
RETURN_FALSE;
20622048
}
20632049
module_number = module->module_number;
@@ -2542,7 +2528,7 @@ PHP_FUNCTION(move_uploaded_file)
25422528
if (successful) {
25432529
zend_hash_str_del(SG(rfc1867_uploaded_files), path, path_len);
25442530
} else {
2545-
php_error_docref(NULL, E_WARNING, "Unable to move '%s' to '%s'", path, new_path);
2531+
php_error_docref(NULL, E_WARNING, "Unable to move \"%s\" to \"%s\"", path, new_path);
25462532
}
25472533

25482534
RETURN_BOOL(successful);

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ function localeconv(): array {}
678678

679679
function strnatcasecmp(string $s1, string $s2): int {}
680680

681-
function substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int|false {}
681+
function substr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int {}
682682

683683
function str_pad(string $input, int $pad_length, string $pad_string = " ", int $pad_type = STR_PAD_RIGHT): string {}
684684

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 251fc9f272492ab76c4a1a1dabcd768269cf1bde */
2+
* Stub hash: d64a15de5772960be65773ccb79e0227bae0eac0 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -1045,7 +1045,7 @@ ZEND_END_ARG_INFO()
10451045

10461046
#define arginfo_strnatcasecmp arginfo_strnatcmp
10471047

1048-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_count, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
1048+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_substr_count, 0, 2, IS_LONG, 0)
10491049
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
10501050
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
10511051
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0")

ext/standard/browscap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static int browscap_read_file(char *filename, browser_data *browdata, int persis
413413

414414
zend_stream_init_fp(&fh, VCWD_FOPEN(filename, "r"), filename);
415415
if (!fh.handle.fp) {
416-
zend_error(E_CORE_WARNING, "Cannot open '%s' for reading", filename);
416+
zend_error(E_CORE_WARNING, "Cannot open \"%s\" for reading", filename);
417417
return FAILURE;
418418
}
419419

ext/standard/dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ PHP_FUNCTION(glob)
415415
ZEND_PARSE_PARAMETERS_END();
416416

417417
if (pattern_len >= MAXPATHLEN) {
418-
php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
419-
RETURN_FALSE;
418+
zend_argument_value_error(1, "must have a length less than %d bytes", MAXPATHLEN);
419+
RETURN_THROWS();
420420
}
421421

422422
if ((GLOB_AVAILABLE_FLAGS & flags) != flags) {

ext/standard/dl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ PHPAPI PHP_FUNCTION(dl)
5454
}
5555

5656
if (filename_len >= MAXPATHLEN) {
57-
php_error_docref(NULL, E_WARNING, "File name exceeds the maximum allowed length of %d characters", MAXPATHLEN);
58-
RETURN_FALSE;
57+
zend_argument_value_error(1, "must be shorter than %d bytes", MAXPATHLEN);
58+
RETURN_THROWS();
5959
}
6060

6161
php_dl(filename, MODULE_TEMPORARY, return_value, 0);

ext/standard/file.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -945,9 +945,9 @@ PHP_FUNCTION(popen)
945945

946946
/* Musl only partially validates the mode. Manually check it to ensure consistent behavior. */
947947
if (mode_len != 1 || (*posix_mode != 'r' && *posix_mode != 'w')) {
948-
php_error_docref2(NULL, command, posix_mode, E_WARNING, "Invalid mode");
948+
zend_argument_value_error(2, "must be either \"r\" or \"w\"");
949949
efree(posix_mode);
950-
RETURN_FALSE;
950+
RETURN_THROWS();
951951
}
952952
#endif
953953

@@ -1816,7 +1816,7 @@ PHP_FUNCTION(fputcsv)
18161816
zend_argument_value_error(3, "must be a single character");
18171817
RETURN_THROWS();
18181818
} else if (delimiter_str_len > 1) {
1819-
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
1819+
php_error_docref(NULL, E_WARNING, "Argument #3 ($delimiter) must be a single character");
18201820
}
18211821

18221822
/* use first character from string */
@@ -1828,15 +1828,15 @@ PHP_FUNCTION(fputcsv)
18281828
zend_argument_value_error(4, "must be a single character");
18291829
RETURN_THROWS();
18301830
} else if (enclosure_str_len > 1) {
1831-
php_error_docref(NULL, E_NOTICE, "enclosure must be a single character");
1831+
php_error_docref(NULL, E_WARNING, "Argument #4 ($enclosure) must be a single character");
18321832
}
18331833
/* use first character from string */
18341834
enclosure = *enclosure_str;
18351835
}
18361836

18371837
if (escape_str != NULL) {
18381838
if (escape_str_len > 1) {
1839-
php_error_docref(NULL, E_NOTICE, "escape must be empty or a single character");
1839+
php_error_docref(NULL, E_WARNING, "Argument #5 ($escape) must be empty or a single character");
18401840
}
18411841
if (escape_str_len < 1) {
18421842
escape_char = PHP_CSV_NO_ESCAPE;
@@ -1954,7 +1954,7 @@ PHP_FUNCTION(fgetcsv)
19541954
zend_argument_value_error(3, "must be a single character");
19551955
RETURN_THROWS();
19561956
} else if (delimiter_str_len > 1) {
1957-
php_error_docref(NULL, E_NOTICE, "delimiter must be a single character");
1957+
php_error_docref(NULL, E_WARNING, "Argument #3 ($delimiter) must be a single character");
19581958
}
19591959

19601960
/* use first character from string */
@@ -1966,7 +1966,7 @@ PHP_FUNCTION(fgetcsv)
19661966
zend_argument_value_error(4, "must be a single character");
19671967
RETURN_THROWS();
19681968
} else if (enclosure_str_len > 1) {
1969-
php_error_docref(NULL, E_NOTICE, "enclosure must be a single character");
1969+
php_error_docref(NULL, E_WARNING, "Argument #4 ($enclosure) must be a single character");
19701970
}
19711971

19721972
/* use first character from string */
@@ -1975,7 +1975,7 @@ PHP_FUNCTION(fgetcsv)
19751975

19761976
if (escape_str != NULL) {
19771977
if (escape_str_len > 1) {
1978-
php_error_docref(NULL, E_NOTICE, "escape must be empty or a single character");
1978+
php_error_docref(NULL, E_WARNING, "Argument #5 ($enclosure) must be empty or a single character");
19791979
}
19801980

19811981
if (escape_str_len < 1) {
@@ -2423,12 +2423,12 @@ PHP_FUNCTION(fnmatch)
24232423
ZEND_PARSE_PARAMETERS_END();
24242424

24252425
if (filename_len >= MAXPATHLEN) {
2426-
php_error_docref(NULL, E_WARNING, "Filename exceeds the maximum allowed length of %d characters", MAXPATHLEN);
2427-
RETURN_FALSE;
2426+
zend_argument_value_error(1, "must have a length less than %d bytes", MAXPATHLEN);
2427+
RETURN_THROWS();
24282428
}
24292429
if (pattern_len >= MAXPATHLEN) {
2430-
php_error_docref(NULL, E_WARNING, "Pattern exceeds the maximum allowed length of %d characters", MAXPATHLEN);
2431-
RETURN_FALSE;
2430+
zend_argument_value_error(2, "must have a length less than %d bytes", MAXPATHLEN);
2431+
RETURN_THROWS();
24322432
}
24332433

24342434
RETURN_BOOL( ! fnmatch( pattern, filename, (int)flags ));

ext/standard/ftok.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ PHP_FUNCTION(ftok)
4545
}
4646

4747
if (proj_len != 1){
48-
php_error_docref(NULL, E_WARNING, "Project identifier is invalid");
49-
RETURN_LONG(-1);
48+
zend_argument_value_error(2, "must be 1 byte long");
49+
RETURN_THROWS();
5050
}
5151

5252
if (php_check_open_basedir(pathname)) {

0 commit comments

Comments
 (0)