Skip to content

Use a common function for "cannot be empty" ValueError #15489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 21, 2024
4 changes: 2 additions & 2 deletions Zend/tests/property_hooks/invalid_empty_hooks.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--TEST--
Property hook list cannot be empty
Property hook list must not be empty
--FILE--
<?php

Expand All @@ -9,4 +9,4 @@ class Test {

?>
--EXPECTF--
Fatal error: Property hook list cannot be empty in %s on line %d
Fatal error: Property hook list must not be empty in %s on line %d
5 changes: 5 additions & 0 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *
}
/* }}} */

ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num)
{
zend_argument_value_error(arg_num, "must not be empty");
}

ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, zend_class_entry *old_ce)
{
if (old_ce->type == ZEND_INTERNAL_CLASS) {
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -1564,6 +1564,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_en
ZEND_API ZEND_COLD void zend_argument_error(zend_class_entry *error_ce, uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_type_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format, ...);
ZEND_API ZEND_COLD void zend_argument_must_not_be_empty_error(uint32_t arg_num);
ZEND_API ZEND_COLD void zend_class_redeclaration_error(int type, zend_class_entry *old_ce);
ZEND_API ZEND_COLD void zend_class_redeclaration_error_ex(int type, zend_string *new_name, zend_class_entry *old_ce);

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8383,7 +8383,7 @@ static void zend_compile_property_hooks(
zend_class_entry *ce = CG(active_class_entry);

if (hooks->children == 0) {
zend_error_noreturn(E_COMPILE_ERROR, "Property hook list cannot be empty");
zend_error_noreturn(E_COMPILE_ERROR, "Property hook list must not be empty");
}

for (uint32_t i = 0; i < hooks->children; i++) {
Expand Down
2 changes: 1 addition & 1 deletion ext/bz2/bz2.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ PHP_FUNCTION(bzopen)
/* If it's not a resource its a string containing the filename to open */
if (Z_TYPE_P(file) == IS_STRING) {
if (Z_STRLEN_P(file) == 0) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/bz2/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ var_dump(bzopen($fp, "r"));

?>
--EXPECTF--
bzopen(): Argument #1 ($file) cannot be empty
bzopen(): Argument #1 ($file) cannot be empty
bzopen(): Argument #1 ($file) must not be empty
bzopen(): Argument #1 ($file) must not be empty
bzopen(): Argument #2 ($mode) must be either "r" or "w"
bzopen(): Argument #2 ($mode) must be either "r" or "w"
bzopen(): Argument #2 ($mode) must be either "r" or "w"
Expand Down
11 changes: 3 additions & 8 deletions ext/dba/dba.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,15 +547,15 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
}

if (ZSTR_LEN(path) == 0) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}
if (ZSTR_LEN(mode) == 0) {
zend_argument_value_error(2, "cannot be empty");
zend_argument_must_not_be_empty_error(2);
RETURN_THROWS();
}
if (handler_str && ZSTR_LEN(handler_str) == 0) {
zend_argument_value_error(3, "cannot be empty");
zend_argument_must_not_be_empty_error(3);
RETURN_THROWS();
}
// TODO Check Value for permission
Expand Down Expand Up @@ -639,11 +639,6 @@ static void php_dba_open(INTERNAL_FUNCTION_PARAMETERS, bool persistent)
bool is_lock_ignored = false;
// bool is_file_lock = false;

if (ZSTR_LEN(mode) == 0) {
zend_argument_value_error(2, "cannot be empty");
efree(resource_key);
RETURN_THROWS();
}
if (ZSTR_LEN(mode) > 3) {
zend_argument_value_error(2, "must be at most 3 characters");
efree(resource_key);
Expand Down
12 changes: 6 additions & 6 deletions ext/dba/tests/value_errors_open.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ object(Dba\Connection)#%d (%d) {

Warning: dba_open(): Handler "bogus" is not available in %s on line %d
bool(false)
dba_open(): Argument #1 ($path) cannot be empty
dba_open(): Argument #2 ($mode) cannot be empty
dba_open(): Argument #3 ($handler) cannot be empty
dba_open(): Argument #1 ($path) must not be empty
dba_open(): Argument #2 ($mode) must not be empty
dba_open(): Argument #3 ($handler) must not be empty
dba_open(): Argument #2 ($mode) first character must be one of "r", "w", "c", or "n"
dba_open(): Argument #2 ($mode) second character must be one of "d", "l", "-", or "t"
dba_open(): Argument #2 ($mode) third character must be "t"
Expand All @@ -133,9 +133,9 @@ dba_open(): Argument #5 ($map_size) must be greater than or equal to 0

Warning: dba_popen(): Handler "bogus" is not available in %s on line %d
bool(false)
dba_popen(): Argument #1 ($path) cannot be empty
dba_popen(): Argument #2 ($mode) cannot be empty
dba_popen(): Argument #3 ($handler) cannot be empty
dba_popen(): Argument #1 ($path) must not be empty
dba_popen(): Argument #2 ($mode) must not be empty
dba_popen(): Argument #3 ($handler) must not be empty
dba_popen(): Argument #2 ($mode) first character must be one of "r", "w", "c", or "n"
dba_popen(): Argument #2 ($mode) second character must be one of "d", "l", "-", or "t"
dba_popen(): Argument #2 ($mode) third character must be "t"
Expand Down
12 changes: 6 additions & 6 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode)
}

if (!source_len) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}
if (ZEND_SIZE_T_INT_OVFL(source_len)) {
Expand Down Expand Up @@ -1579,7 +1579,7 @@ PHP_METHOD(DOMDocument, save)
}

if (file_len == 0) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down Expand Up @@ -1883,7 +1883,7 @@ static void dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
}

if (!source_len) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down Expand Up @@ -1992,7 +1992,7 @@ static void dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type
}

if (!source_len) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down Expand Up @@ -2085,7 +2085,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
}

if (!source_len) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down Expand Up @@ -2162,7 +2162,7 @@ PHP_METHOD(DOMDocument, saveHTMLFile)
}

if (file_len == 0) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/domimplementation.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PHP_METHOD(DOMImplementation, createDocumentType)
}

if (name_len == 0) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/dom/element.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ PHP_METHOD(DOMElement, setAttribute)
}

if (name_len == 0) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down Expand Up @@ -903,7 +903,7 @@ PHP_METHOD(DOMElement, getAttributeNS)
static void dom_set_attribute_ns_legacy(dom_object *intern, xmlNodePtr elemp, char *uri, size_t uri_len, char *name, size_t name_len, const char *value)
{
if (name_len == 0) {
zend_argument_value_error(2, "cannot be empty");
zend_argument_must_not_be_empty_error(2);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/html_document.c
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ PHP_METHOD(Dom_HTMLDocument, saveHtmlFile)
}

if (file_len == 0) {
zend_argument_value_error(1, "must not be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $dom = Dom\HTMLDocument::createFromFile("");

?>
--EXPECTF--
Fatal error: Uncaught ValueError: Path cannot be empty in %s:%d
Fatal error: Uncaught ValueError: Path must not be empty in %s:%d
Stack trace:
#0 %s(%d): Dom\HTMLDocument::createFromFile('')
#1 {main}
Expand Down
2 changes: 1 addition & 1 deletion ext/enchant/enchant.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ PHP_FUNCTION(enchant_broker_request_dict)
PHP_ENCHANT_GET_BROKER;

if (taglen == 0) {
zend_argument_value_error(2, "cannot be empty");
zend_argument_must_not_be_empty_error(2);
RETURN_THROWS();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ try {

?>
--EXPECT--
enchant_broker_request_dict(): Argument #2 ($tag) cannot be empty
enchant_broker_request_dict(): Argument #2 ($tag) must not be empty
4 changes: 2 additions & 2 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -4550,7 +4550,7 @@ PHP_FUNCTION(exif_read_data)
}

if (!Z_STRLEN_P(stream)) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down Expand Up @@ -4727,7 +4727,7 @@ PHP_FUNCTION(exif_thumbnail)
}

if (!Z_STRLEN_P(stream)) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
RETURN_THROWS();
}

Expand Down
4 changes: 2 additions & 2 deletions ext/exif/tests/filename_empty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ try {

?>
--EXPECT--
exif_read_data(): Argument #1 ($file) cannot be empty
exif_thumbnail(): Argument #1 ($file) cannot be empty
exif_read_data(): Argument #1 ($file) must not be empty
exif_thumbnail(): Argument #1 ($file) must not be empty
exif_read_data(): Argument #1 ($file) must not contain any null bytes
exif_thumbnail(): Argument #1 ($file) must not contain any null bytes
2 changes: 1 addition & 1 deletion ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
php_stream_statbuf ssb;

if (buffer == NULL || buffer_len == 0) {
zend_argument_value_error(1, "cannot be empty");
zend_argument_must_not_be_empty_error(1);
goto clean;
}
if (CHECK_NULL_PATH(buffer, buffer_len)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/fileinfo/tests/finfo_file_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var_dump(finfo_file($fp, '&'));
?>
--EXPECTF--
finfo_file(): Argument #1 ($finfo) must not contain any null bytes
finfo_file(): Argument #1 ($finfo) cannot be empty
finfo_file(): Argument #1 ($finfo) must not be empty
string(9) "directory"

Warning: finfo_file(&): Failed to open stream: No such file or directory in %s on line %d
Expand Down
2 changes: 1 addition & 1 deletion ext/fileinfo/tests/mime_content_type_001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ mime_content_type(): Argument #1 ($filename) must be of type resource|string, st
mime_content_type(): Argument #1 ($filename) must be of type resource|string, array given

Warning: mime_content_type(foo/inexistent): Failed to open stream: No such file or directory in %s on line %d
mime_content_type(): Argument #1 ($filename) cannot be empty
mime_content_type(): Argument #1 ($filename) must not be empty
mime_content_type(): Argument #1 ($filename) must not contain any null bytes
2 changes: 1 addition & 1 deletion ext/filter/logical_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */

if (thousand_set) {
if (thousand_len < 1) {
zend_value_error("%s(): \"thousand\" option cannot be empty", get_active_function_name());
zend_value_error("%s(): \"thousand\" option must not be empty", get_active_function_name());
RETURN_VALIDATION_FAILED
} else {
tsd_sep = thousand;
Expand Down
2 changes: 1 addition & 1 deletion ext/filter/tests/bug51368.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ try {
--EXPECT--
float(1000)
float(1234.567)
filter_var(): "thousand" option cannot be empty
filter_var(): "thousand" option must not be empty
2 changes: 1 addition & 1 deletion ext/gd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ PHP_FUNCTION(imagesetstyle)

num_styles = zend_hash_num_elements(Z_ARRVAL_P(styles));
if (num_styles == 0) {
zend_argument_value_error(2, "cannot be empty");
zend_argument_must_not_be_empty_error(2);
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/gd/tests/bug72709.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ imagedestroy($im);
?>
====DONE====
--EXPECT--
imagesetstyle(): Argument #2 ($style) cannot be empty
imagesetstyle(): Argument #2 ($style) must not be empty
====DONE====
12 changes: 1 addition & 11 deletions ext/gettext/gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ZEND_GET_MODULE(php_gettext)
zend_argument_value_error(_arg_num, "is too long"); \
RETURN_THROWS(); \
} else if (domain_len == 0) { \
zend_argument_value_error(_arg_num, "cannot be empty"); \
zend_argument_must_not_be_empty_error(_arg_num); \
RETURN_THROWS(); \
}

Expand Down Expand Up @@ -190,11 +190,6 @@ PHP_FUNCTION(bindtextdomain)

PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))

if (!ZSTR_LEN(domain)) {
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

if (dir == NULL) {
RETURN_STRING(bindtextdomain(ZSTR_VAL(domain), NULL));
}
Expand Down Expand Up @@ -312,11 +307,6 @@ PHP_FUNCTION(bind_textdomain_codeset)

PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))

if (!ZSTR_LEN(domain)) {
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}

retval = bind_textdomain_codeset(ZSTR_VAL(domain), codeset ? ZSTR_VAL(codeset) : NULL);

if (!retval) {
Expand Down
4 changes: 2 additions & 2 deletions ext/gettext/tests/dcngettext.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ string(1) "1"
string(4) "test"
string(4) "test"
string(4) "test"
dcngettext(): Argument #1 ($domain) cannot be empty
dcngettext(): Argument #1 ($domain) cannot be empty
dcngettext(): Argument #1 ($domain) must not be empty
dcngettext(): Argument #1 ($domain) must not be empty
Done
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ gettext
echo "Done\n";
?>
--EXPECT--
bind_textdomain_codeset(): Argument #1 ($domain) cannot be empty
bind_textdomain_codeset(): Argument #1 ($domain) cannot be empty
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
string(5) "UTF-8"
Done
--CREDITS--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ try {

?>
--EXPECT--
bindtextdomain(): Argument #1 ($domain) cannot be empty
bindtextdomain(): Argument #1 ($domain) must not be empty
--CREDITS--
Till Klampaeckel, till@php.net
PHP Testfest Berlin 2009-05-09
2 changes: 1 addition & 1 deletion ext/gettext/tests/gettext_textdomain-retval.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test
test
foo
textdomain(): Argument #1 ($domain) cannot be zero
textdomain(): Argument #1 ($domain) cannot be empty
textdomain(): Argument #1 ($domain) must not be empty
--CREDITS--
Christian Weiske, cweiske@php.net
PHP Testfest Berlin 2009-05-09
Loading
Loading