Skip to content

Commit c37a1cd

Browse files
committed
Promote a few remaining errors in ext/standard
Closes phpGH-6110
1 parent 62c20c6 commit c37a1cd

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

+1222
-1072
lines changed

Zend/tests/bug41026.phpt

+1-1
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -2233,8 +2233,7 @@ PHP_FUNCTION(mb_strcut)
22332233
}
22342234

22352235
if (from > string.len) {
2236-
// TODO Out of bounds ValueError
2237-
RETURN_FALSE;
2236+
RETURN_EMPTY_STRING();
22382237
}
22392238

22402239
ret = mbfl_strcut(&string, &result, from, len);
@@ -3500,6 +3499,9 @@ PHP_FUNCTION(mb_send_mail)
35003499
str_headers = php_trim(str_headers, NULL, 0, 2);
35013500
} else if (headers_ht) {
35023501
str_headers = php_mail_build_headers(headers_ht);
3502+
if (EG(exception)) {
3503+
RETURN_THROWS();
3504+
}
35033505
}
35043506

35053507
zend_hash_init(&ht_headers, 0, NULL, ZVAL_PTR_DTOR, 0);

ext/mbstring/mbstring.stub.php

+1-1
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/mbstring_arginfo.h

+2-7
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: 442b9dc473714c91663fcd530214935ba74302e4 */
2+
* Stub hash: e02a0588d1f46fa96452558e35ea904907b8bdf2 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_language, 0, 0, MAY_BE_STRING|MAY_BE_BOOL)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, language, IS_STRING, 1, "null")
@@ -87,12 +87,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mb_substr, 0, 2, IS_STRING, 0)
8787
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
8888
ZEND_END_ARG_INFO()
8989

90-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_mb_strcut, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
91-
ZEND_ARG_TYPE_INFO(0, str, IS_STRING, 0)
92-
ZEND_ARG_TYPE_INFO(0, start, IS_LONG, 0)
93-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 1, "null")
94-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null")
95-
ZEND_END_ARG_INFO()
90+
#define arginfo_mb_strcut arginfo_mb_substr
9691

9792
#define arginfo_mb_strwidth arginfo_mb_strlen
9893

ext/mbstring/tests/bug49354.phpt

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ 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'));
1313
var_dump(mb_strcut($crap, 13, 100, 'UTF-8'));
14+
1415
?>
1516
--EXPECT--
1617
string(12) "AåBäCöDü"
1718
string(11) "åBäCöDü"
1819
string(11) "åBäCöDü"
1920
string(9) "BäCöDü"
2021
string(0) ""
21-
bool(false)
22+
string(0) ""

ext/mbstring/tests/mb_strcut.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ 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

3131
$str = mb_strcut($euc_jp, 100, 10,'EUC-JP');
32-
($str === false) ? print "OK\n" : print "No good\n";
32+
($str === "") ? print "OK\n" : print "No good\n";
3333

3434
$str = mb_strcut($euc_jp, -100, 10,'EUC-JP');
3535
($str !== "") ? print "OK\n" : print "No good\n";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
mysqli_real_connect() with compression
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifemb.inc');
7+
require_once('skipifconnectfailure.inc');
8+
?>
9+
--INI--
10+
mysqli.allow_local_infile=1
11+
--FILE--
12+
<?php
13+
14+
include("connect.inc");
15+
16+
$mysqli = mysqli_init();
17+
$result = my_mysqli_real_connect($mysqli, $host, $user, $passwd, "", $port, $socket, MYSQLI_CLIENT_COMPRESS);
18+
19+
$mysqli->query("DROP TABLE IF EXISTS test");
20+
$create = "CREATE TABLE test (blob BLOB NOT NULL DEFAULT '')";
21+
22+
$data = str_repeat("x", 16 * 1024 * 1024);
23+
$mysqli->query("INSERT INTO test(`blob`) VALUE ('$data')");
24+
25+
var_dump(mysqli_error_list($mysqli));
26+
$mysqli->close();
27+
28+
?>
29+
--CLEAN--
30+
<?php
31+
require_once("clean_table.inc");
32+
?>
33+
--EXPECT--

ext/opcache/Optimizer/zend_func_info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static const func_info_t func_infos[] = {
533533
F1("mb_stristr", MAY_BE_FALSE | MAY_BE_STRING),
534534
F1("mb_strrichr", MAY_BE_FALSE | MAY_BE_STRING),
535535
F1("mb_substr", MAY_BE_STRING),
536-
F1("mb_strcut", MAY_BE_FALSE | MAY_BE_STRING),
536+
F1("mb_strcut", MAY_BE_STRING),
537537
F1("mb_strimwidth", MAY_BE_STRING),
538538
F1("mb_convert_encoding", MAY_BE_FALSE | MAY_BE_STRING | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY),
539539
F1("mb_detect_encoding", MAY_BE_FALSE | MAY_BE_STRING),

ext/sodium/libsodium.c

+1-1
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

+1-17
Original file line numberDiff line numberDiff line change
@@ -962,22 +962,6 @@ static int php_array_user_compare(Bucket *a, Bucket *b) /* {{{ */
962962
}
963963
/* }}} */
964964

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

ext/standard/basic_functions.c

+24-38
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ 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");
1313+
php_error_docref(NULL, E_WARNING, "Argument #1 ($timestamp) must be greater than or equal to the current time");
13141314
RETURN_FALSE;
13151315
}
13161316

@@ -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

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ function localeconv(): array {}
672672

673673
function strnatcasecmp(string $s1, string $s2): int {}
674674

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

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

ext/standard/basic_functions_arginfo.h

+7-7
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: 26683100d272e35a6318e0eaece65dc3761b7b03 */
2+
* Stub hash: 0224dc521c4a8bd49fbcfd26cddb01a2e571cf74 */
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)
@@ -743,7 +743,7 @@ ZEND_END_ARG_INFO()
743743
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_setrawcookie, 0, 1, _IS_BOOL, 0)
744744
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
745745
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, value, IS_STRING, 0, "\'\'")
746-
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, expires_or_options, "0")
746+
ZEND_ARG_TYPE_MASK(0, expires_or_options, MAY_BE_ARRAY|MAY_BE_LONG, "0")
747747
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 0, "\'\'")
748748
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, domain, IS_STRING, 0, "\'\'")
749749
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, secure, _IS_BOOL, 0, "false")
@@ -932,9 +932,9 @@ ZEND_END_ARG_INFO()
932932

933933
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_replace, 0, 3, MAY_BE_STRING|MAY_BE_ARRAY|MAY_BE_FALSE)
934934
ZEND_ARG_TYPE_MASK(0, str, MAY_BE_ARRAY|MAY_BE_STRING, NULL)
935-
ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_STRING|MAY_BE_ARRAY, NULL)
936-
ZEND_ARG_INFO(0, start)
937-
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, length, "null")
935+
ZEND_ARG_TYPE_MASK(0, replace, MAY_BE_ARRAY|MAY_BE_STRING, NULL)
936+
ZEND_ARG_TYPE_MASK(0, start, MAY_BE_ARRAY|MAY_BE_LONG, NULL)
937+
ZEND_ARG_TYPE_MASK(0, length, MAY_BE_ARRAY|MAY_BE_LONG|MAY_BE_NULL, "null")
938938
ZEND_END_ARG_INFO()
939939

940940
#define arginfo_quotemeta arginfo_base64_encode
@@ -1042,7 +1042,7 @@ ZEND_END_ARG_INFO()
10421042

10431043
#define arginfo_strnatcasecmp arginfo_strnatcmp
10441044

1045-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_substr_count, 0, 2, MAY_BE_LONG|MAY_BE_FALSE)
1045+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_substr_count, 0, 2, IS_LONG, 0)
10461046
ZEND_ARG_TYPE_INFO(0, haystack, IS_STRING, 0)
10471047
ZEND_ARG_TYPE_INFO(0, needle, IS_STRING, 0)
10481048
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, offset, IS_LONG, 0, "0")
@@ -1770,7 +1770,7 @@ ZEND_END_ARG_INFO()
17701770

17711771
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_password_needs_rehash, 0, 2, _IS_BOOL, 0)
17721772
ZEND_ARG_TYPE_INFO(0, hash, IS_STRING, 0)
1773-
ZEND_ARG_TYPE_MASK(0, algo, MAY_BE_STRING|MAY_BE_LONG, NULL)
1773+
ZEND_ARG_TYPE_MASK(0, algo, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_NULL, NULL)
17741774
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
17751775
ZEND_END_ARG_INFO()
17761776

ext/standard/browscap.c

+1-1
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/dl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ 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);
57+
php_error_docref(NULL, E_WARNING, "Filename exceeds the maximum allowed length of %d characters", MAXPATHLEN);
5858
RETURN_FALSE;
5959
}
6060

0 commit comments

Comments
 (0)