diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 11fec690723e..b6b04cb269f4 100644 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -310,12 +310,16 @@ PHP_FUNCTION(spl_autoload) { int pos_len, pos1_len; char *pos, *pos1; - zend_string *class_name, *lc_name, *file_exts = SPL_G(autoload_extensions); + zend_string *class_name, *lc_name, *file_exts = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S", &class_name, &file_exts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!", &class_name, &file_exts) == FAILURE) { RETURN_THROWS(); } + if (!file_exts) { + file_exts = SPL_G(autoload_extensions); + } + if (file_exts == NULL) { /* autoload_extensions is not initialized, set to defaults */ pos = SPL_DEFAULT_FILE_EXTENSIONS; pos_len = sizeof(SPL_DEFAULT_FILE_EXTENSIONS) - 1; @@ -347,9 +351,10 @@ PHP_FUNCTION(spl_autoload_extensions) { zend_string *file_exts = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S", &file_exts) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &file_exts) == FAILURE) { RETURN_THROWS(); } + if (file_exts) { if (SPL_G(autoload_extensions)) { zend_string_release_ex(SPL_G(autoload_extensions), 0); @@ -513,11 +518,11 @@ PHP_FUNCTION(spl_autoload_register) zend_object *obj_ptr; zend_fcall_info_cache fcc; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|zbb", &zcallable, &do_throw, &prepend) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z!bb", &zcallable, &do_throw, &prepend) == FAILURE) { RETURN_THROWS(); } - if (ZEND_NUM_ARGS()) { + if (zcallable) { if (!zend_is_callable_ex(zcallable, NULL, 0, &func_name, &fcc, &error)) { alfi.ce = fcc.calling_scope; alfi.func_ptr = fcc.function_handler; diff --git a/ext/spl/php_spl.stub.php b/ext/spl/php_spl.stub.php index 8811e1913a2b..8e2a6edf0a93 100755 --- a/ext/spl/php_spl.stub.php +++ b/ext/spl/php_spl.stub.php @@ -8,16 +8,16 @@ function class_parents($instance, bool $autoload = true): array|false {} function class_uses($what, bool $autoload = true): array|false {} -function spl_autoload(string $class_name, string $file_extensions = UNKNOWN): void {} +function spl_autoload(string $class_name, ?string $file_extensions = null): void {} // This silently ignores non-string class names function spl_autoload_call($class_name): void {} -function spl_autoload_extensions(string $file_extensions = UNKNOWN): string {} +function spl_autoload_extensions(?string $file_extensions = null): string {} function spl_autoload_functions(): array|false {} -function spl_autoload_register($autoload_function = UNKNOWN, bool $throw = true, bool $prepend = false): bool {} +function spl_autoload_register($autoload_function = null, bool $throw = true, bool $prepend = false): bool {} function spl_autoload_unregister($autoload_function): bool {} diff --git a/ext/spl/php_spl_arginfo.h b/ext/spl/php_spl_arginfo.h index 0b19431fd45a..f02c9d22e328 100644 --- a/ext/spl/php_spl_arginfo.h +++ b/ext/spl/php_spl_arginfo.h @@ -14,7 +14,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, class_name, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, file_extensions, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_extensions, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_call, 0, 1, IS_VOID, 0) @@ -22,14 +22,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_call, 0, 1, IS_VOID ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_extensions, 0, 0, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, file_extensions, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_extensions, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_spl_autoload_functions, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_spl_autoload_register, 0, 0, _IS_BOOL, 0) - ZEND_ARG_INFO(0, autoload_function) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, autoload_function, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, throw, _IS_BOOL, 0, "true") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, prepend, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() diff --git a/ext/sqlite3/sqlite3.stub.php b/ext/sqlite3/sqlite3.stub.php index 42ba303b00b0..1d6357c3e110 100644 --- a/ext/sqlite3/sqlite3.stub.php +++ b/ext/sqlite3/sqlite3.stub.php @@ -86,10 +86,10 @@ class SQLite3Stmt private function __construct(SQLite3 $sqlite3, string $sql) {} /** @return bool */ - public function bindParam($param_number, &$param, int $type = UNKNOWN) {} + public function bindParam($param_number, &$param, int $type = SQLITE3_TEXT) {} /** @return bool */ - public function bindValue($param_number, $param, int $type = UNKNOWN) {} + public function bindValue($param_number, $param, int $type = SQLITE3_TEXT) {} /** @return bool */ public function clear() {} diff --git a/ext/sqlite3/sqlite3_arginfo.h b/ext/sqlite3/sqlite3_arginfo.h index ab79449ddafd..ecc934c69072 100644 --- a/ext/sqlite3/sqlite3_arginfo.h +++ b/ext/sqlite3/sqlite3_arginfo.h @@ -105,13 +105,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Stmt_bindParam, 0, 0, 2) ZEND_ARG_INFO(0, param_number) ZEND_ARG_INFO(1, param) - ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "SQLITE3_TEXT") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_SQLite3Stmt_bindValue, 0, 0, 2) ZEND_ARG_INFO(0, param_number) ZEND_ARG_INFO(0, param) - ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, type, IS_LONG, 0, "SQLITE3_TEXT") ZEND_END_ARG_INFO() #define arginfo_class_SQLite3Stmt_clear arginfo_class_SQLite3_close diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 4477523edf5f..802f9a0caa22 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -1012,7 +1012,7 @@ static void php_xml_parser_create_impl(INTERNAL_FUNCTION_PARAMETERS, int ns_supp XML_Char *encoding; - if (zend_parse_parameters(ZEND_NUM_ARGS(), (ns_support ? "|ss": "|s"), &encoding_param, &encoding_param_len, &ns_param, &ns_param_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), (ns_support ? "|s!s": "|s!"), &encoding_param, &encoding_param_len, &ns_param, &ns_param_len) == FAILURE) { RETURN_THROWS(); } diff --git a/ext/xml/xml.stub.php b/ext/xml/xml.stub.php index 9693eeba8162..36c67645c62c 100644 --- a/ext/xml/xml.stub.php +++ b/ext/xml/xml.stub.php @@ -2,9 +2,9 @@ /** @generate-function-entries */ -function xml_parser_create(string $encoding = UNKNOWN): XmlParser|false {} +function xml_parser_create(?string $encoding = null): XmlParser|false {} -function xml_parser_create_ns(string $encoding = UNKNOWN, string $sep = ':'): XmlParser|false {} +function xml_parser_create_ns(?string $encoding = null, string $sep = ':'): XmlParser|false {} function xml_set_object(XmlParser $parser, object $obj): bool {} @@ -40,7 +40,7 @@ function xml_set_end_namespace_decl_handler(XmlParser $parser, $hdl): bool {} function xml_parse(XmlParser $parser, string $data, bool $isfinal = false): int {} -function xml_parse_into_struct(XmlParser $parser, string $data, &$values, &$index = UNKNOWN): int {} +function xml_parse_into_struct(XmlParser $parser, string $data, &$values, &$index = null): int {} function xml_get_error_code(XmlParser $parser): int {} diff --git a/ext/xml/xml_arginfo.h b/ext/xml/xml_arginfo.h index 1e448ac81614..e567bbea154b 100644 --- a/ext/xml/xml_arginfo.h +++ b/ext/xml/xml_arginfo.h @@ -1,11 +1,11 @@ /* This is a generated file, edit the .stub.php file instead. */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xml_parser_create, 0, 0, XmlParser, MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_xml_parser_create_ns, 0, 0, XmlParser, MAY_BE_FALSE) - ZEND_ARG_TYPE_INFO(0, encoding, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, sep, IS_STRING, 0, "\':\'") ZEND_END_ARG_INFO() @@ -49,7 +49,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_parse_into_struct, 0, 3, IS_ ZEND_ARG_OBJ_INFO(0, parser, XmlParser, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_INFO(1, values) - ZEND_ARG_INFO(1, index) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(1, index, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_xml_get_error_code, 0, 1, IS_LONG, 0) diff --git a/ext/xmlreader/php_xmlreader.c b/ext/xmlreader/php_xmlreader.c index acb39a7fc973..50715f3db024 100644 --- a/ext/xmlreader/php_xmlreader.c +++ b/ext/xmlreader/php_xmlreader.c @@ -811,7 +811,7 @@ PHP_METHOD(XMLReader, next) xmlreader_object *intern; char *name = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &name, &name_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &name, &name_len) == FAILURE) { RETURN_THROWS(); } diff --git a/ext/xmlreader/php_xmlreader.stub.php b/ext/xmlreader/php_xmlreader.stub.php index cbf7bb1beec4..9de30e5a7afd 100644 --- a/ext/xmlreader/php_xmlreader.stub.php +++ b/ext/xmlreader/php_xmlreader.stub.php @@ -47,7 +47,7 @@ public function moveToNextAttribute() {} public function read() {} /** @return bool */ - public function next(string $localname = UNKNOWN) {} + public function next(?string $localname = null) {} /** @return bool|XMLReader */ public static function open(string $URI, ?string $encoding = null, int $options = 0) {} diff --git a/ext/xmlreader/php_xmlreader_arginfo.h b/ext/xmlreader/php_xmlreader_arginfo.h index 0b9d28c94405..83a5ce6a2285 100644 --- a/ext/xmlreader/php_xmlreader_arginfo.h +++ b/ext/xmlreader/php_xmlreader_arginfo.h @@ -41,7 +41,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_XMLReader_read arginfo_class_XMLReader_close ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XMLReader_next, 0, 0, 0) - ZEND_ARG_TYPE_INFO(0, localname, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, localname, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XMLReader_open, 0, 0, 1) diff --git a/ext/xsl/php_xsl.stub.php b/ext/xsl/php_xsl.stub.php index 23f187fbddea..9e79c9c63489 100644 --- a/ext/xsl/php_xsl.stub.php +++ b/ext/xsl/php_xsl.stub.php @@ -41,10 +41,10 @@ public function removeParameter(string $namespace, string $name) {} public function hasExsltSupport() {} /** - * @param string|array $restrict + * @param string|array|null $restrict * @return void */ - public function registerPHPFunctions($restrict = UNKNOWN) {} + public function registerPHPFunctions($restrict = null) {} /** @return bool */ public function setProfiling(?string $filename) {} diff --git a/ext/xsl/php_xsl_arginfo.h b/ext/xsl/php_xsl_arginfo.h index e9cc9009ae09..8093a9316fc7 100644 --- a/ext/xsl/php_xsl_arginfo.h +++ b/ext/xsl/php_xsl_arginfo.h @@ -35,7 +35,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_hasExsltSupport, 0, 0, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_registerPHPFunctions, 0, 0, 0) - ZEND_ARG_INFO(0, restrict) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, restrict, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_XSLTProcessor_setProfiling, 0, 0, 1) diff --git a/ext/xsl/xsltprocessor.c b/ext/xsl/xsltprocessor.c index 1ced2b7b7404..815615dec44b 100644 --- a/ext/xsl/xsltprocessor.c +++ b/ext/xsl/xsltprocessor.c @@ -760,13 +760,19 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions) { zval *id = ZEND_THIS; xsl_object *intern; - zval *array_value, *entry, new_string; - zend_string *name; + zval *entry, new_string; + zend_string *restrict_str = NULL; + HashTable *restrict_ht = NULL; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "a", &array_value) == SUCCESS) { - intern = Z_XSL_P(id); + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_ARRAY_HT_OR_NULL(restrict_str, restrict_ht) + ZEND_PARSE_PARAMETERS_END(); + + intern = Z_XSL_P(id); - ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(array_value), entry) { + if (restrict_ht) { + ZEND_HASH_FOREACH_VAL(restrict_ht, entry) { zend_string *str = zval_try_get_string(entry); if (UNEXPECTED(!str)) { return; @@ -777,15 +783,11 @@ PHP_METHOD(XSLTProcessor, registerPHPFunctions) } ZEND_HASH_FOREACH_END(); intern->registerPhpFunctions = 2; - } else if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "S", &name) == SUCCESS) { - intern = Z_XSL_P(id); - - ZVAL_LONG(&new_string,1); - zend_hash_update(intern->registered_phpfunctions, name, &new_string); + } else if (restrict_str) { + ZVAL_LONG(&new_string, 1); + zend_hash_update(intern->registered_phpfunctions, restrict_str, &new_string); intern->registerPhpFunctions = 2; - - } else if (zend_parse_parameters_none() == SUCCESS) { - intern = Z_XSL_P(id); + } else { intern->registerPhpFunctions = 1; } } diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 3b9b07097e50..948f854cbea3 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1519,21 +1519,21 @@ static ZIPARCHIVE_METHOD(setPassword) char *password; size_t password_len; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &password, &password_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (password_len < 1) { RETURN_FALSE; + } + + int res = zip_set_default_password(intern, (const char *)password); + if (res == 0) { + RETURN_TRUE; } else { - int res = zip_set_default_password(intern, (const char *)password); - if (res == 0) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } + RETURN_FALSE; } } /* }}} */ @@ -1664,13 +1664,13 @@ static ZIPARCHIVE_METHOD(addEmptyDir) char *s; zend_long flags = 0; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &dirname, &dirname_len, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (dirname_len<1) { RETURN_FALSE; } @@ -1725,7 +1725,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /* php_error_docref(NULL, E_NOTICE, "Empty string as pattern"); RETURN_FALSE; } - if (options && (php_zip_parse_options(options, &opts) < 0)) { + if (options && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0 && (php_zip_parse_options(options, &opts) < 0)) { RETURN_FALSE; } @@ -1909,13 +1909,13 @@ static ZIPARCHIVE_METHOD(addFromString) int pos = 0; zend_long flags = ZIP_FL_OVERWRITE; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sS|l", &name, &name_len, &buffer, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + ze_obj = Z_ZIP_P(self); if (ze_obj->buffers_cnt) { ze_obj->buffers = (char **)safe_erealloc(ze_obj->buffers, sizeof(char *), (ze_obj->buffers_cnt+1), 0); @@ -1955,12 +1955,12 @@ static ZIPARCHIVE_METHOD(statName) struct zip_stat sb; zend_string *name; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + PHP_ZIP_STAT_PATH(intern, ZSTR_VAL(name), ZSTR_LEN(name), flags, sb); RETURN_SB(&sb); @@ -1977,13 +1977,13 @@ static ZIPARCHIVE_METHOD(statIndex) struct zip_stat sb; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &index, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (zip_stat_index(intern, index, flags, &sb) != 0) { RETURN_FALSE; } @@ -2001,12 +2001,12 @@ static ZIPARCHIVE_METHOD(locateName) zend_long idx = -1; zend_string *name; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|l", &name, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (ZSTR_LEN(name) < 1) { RETURN_FALSE; } @@ -2030,13 +2030,13 @@ static ZIPARCHIVE_METHOD(getNameIndex) const char *name; zend_long flags = 0, index = 0; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &index, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + name = zip_get_name(intern, (int) index, flags); if (name) { @@ -2056,12 +2056,12 @@ static ZIPARCHIVE_METHOD(setArchiveComment) size_t comment_len; char * comment; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &comment, &comment_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (comment_len > 0xffff) { php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); RETURN_FALSE; @@ -2085,12 +2085,12 @@ static ZIPARCHIVE_METHOD(getArchiveComment) const char * comment; int comment_len = 0; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + comment = zip_get_archive_comment(intern, &comment_len, (int)flags); if(comment==NULL) { RETURN_FALSE; @@ -2109,8 +2109,6 @@ static ZIPARCHIVE_METHOD(setCommentName) char * comment, *name; int idx; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &comment, &comment_len) == FAILURE) { RETURN_THROWS(); @@ -2120,6 +2118,8 @@ static ZIPARCHIVE_METHOD(setCommentName) php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } + ZIP_FROM_OBJECT(intern, self); + if (comment_len > 0xffff) { php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); RETURN_FALSE; @@ -2144,13 +2144,13 @@ static ZIPARCHIVE_METHOD(setCommentIndex) char * comment; struct zip_stat sb; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &index, &comment, &comment_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (comment_len > 0xffff) { php_error_docref(NULL, E_WARNING, "Comment must not exceed 65535 bytes"); RETURN_FALSE; @@ -2175,13 +2175,13 @@ static ZIPARCHIVE_METHOD(setExternalAttributesName) zend_long flags=0, opsys, attr; zip_int64_t idx; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|l", &name, &name_len, &opsys, &attr, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } @@ -2207,13 +2207,13 @@ static ZIPARCHIVE_METHOD(setExternalAttributesIndex) zend_long index, flags=0, opsys, attr; struct zip_stat sb; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lll|l", &index, &opsys, &attr, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + PHP_ZIP_STAT_INDEX(intern, index, 0, sb); if (zip_file_set_external_attributes(intern, (zip_uint64_t)index, (zip_flags_t)flags, (zip_uint8_t)(opsys&0xff), (zip_uint32_t)attr) < 0) { @@ -2236,13 +2236,13 @@ static ZIPARCHIVE_METHOD(getExternalAttributesName) zip_uint32_t attr; zip_int64_t idx; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "szz|l", &name, &name_len, &z_opsys, &z_attr, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } @@ -2272,13 +2272,13 @@ static ZIPARCHIVE_METHOD(getExternalAttributesIndex) zip_uint32_t attr; struct zip_stat sb; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "lzz|l", &index, &z_opsys, &z_attr, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + PHP_ZIP_STAT_INDEX(intern, index, 0, sb); if (zip_file_get_external_attributes(intern, (zip_uint64_t)index, (zip_flags_t)flags, &opsys, &attr) < 0) { @@ -2303,13 +2303,13 @@ static ZIPARCHIVE_METHOD(setEncryptionName) char *name, *password = NULL; size_t name_len, password_len; - ZIP_FROM_OBJECT(intern, self); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s!", &name, &name_len, &method, &password, &password_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } @@ -2336,13 +2336,13 @@ static ZIPARCHIVE_METHOD(setEncryptionIndex) char *password = NULL; size_t password_len; - ZIP_FROM_OBJECT(intern, self); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s!", &index, &method, &password, &password_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) { RETURN_FALSE; } @@ -2364,12 +2364,13 @@ static ZIPARCHIVE_METHOD(getCommentName) const char * comment; char *name; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &name, &name_len, &flags) == FAILURE) { RETURN_THROWS(); } + + ZIP_FROM_OBJECT(intern, self); + if (name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); RETURN_FALSE; @@ -2396,13 +2397,13 @@ static ZIPARCHIVE_METHOD(getCommentIndex) zip_uint32_t comment_len = 0; struct zip_stat sb; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &index, &flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + PHP_ZIP_STAT_INDEX(intern, index, 0, sb); comment = zip_file_get_comment(intern, index, &comment_len, (zip_flags_t)flags); RETURN_STRINGL((char *)comment, comment_len); @@ -2420,13 +2421,13 @@ static ZIPARCHIVE_METHOD(setCompressionName) zip_int64_t idx; zend_long comp_method, comp_flags = 0; - ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l", &name, &name_len, &comp_method, &comp_flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, this); + if (name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } @@ -2453,13 +2454,13 @@ static ZIPARCHIVE_METHOD(setCompressionIndex) zend_long index; zend_long comp_method, comp_flags = 0; - ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l", &index, &comp_method, &comp_flags) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, this); + if (zip_set_file_compression(intern, (zip_uint64_t)index, (zip_int32_t)comp_method, (zip_uint32_t)comp_flags) != 0) { RETURN_FALSE; @@ -2480,13 +2481,13 @@ static ZIPARCHIVE_METHOD(setMtimeName) zip_int64_t idx; zend_long mtime, flags = 0; - ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|l", &name, &name_len, &mtime, &flags) == FAILURE) { return; } + ZIP_FROM_OBJECT(intern, this); + if (name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as entry name"); } @@ -2513,13 +2514,13 @@ static ZIPARCHIVE_METHOD(setMtimeIndex) zend_long index; zend_long mtime, flags = 0; - ZIP_FROM_OBJECT(intern, this); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|l", &index, &mtime, &flags) == FAILURE) { return; } + ZIP_FROM_OBJECT(intern, this); + if (zip_file_set_mtime(intern, (zip_uint64_t)index, (time_t)mtime, (zip_uint32_t)flags) != 0) { RETURN_FALSE; @@ -2537,12 +2538,12 @@ static ZIPARCHIVE_METHOD(deleteIndex) zval *self = ZEND_THIS; zend_long index; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (index < 0) { RETURN_FALSE; } @@ -2565,11 +2566,12 @@ static ZIPARCHIVE_METHOD(deleteName) char *name; struct zip_stat sb; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { RETURN_THROWS(); } + + ZIP_FROM_OBJECT(intern, self); + if (name_len < 1) { RETURN_FALSE; } @@ -2592,9 +2594,6 @@ static ZIPARCHIVE_METHOD(renameIndex) size_t new_name_len; zend_long index; - - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &index, &new_name, &new_name_len) == FAILURE) { RETURN_THROWS(); } @@ -2603,13 +2602,17 @@ static ZIPARCHIVE_METHOD(renameIndex) RETURN_FALSE; } + ZIP_FROM_OBJECT(intern, self); + if (new_name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as new entry name"); RETURN_FALSE; } + if (zip_file_rename(intern, index, (const char *)new_name, 0) != 0) { RETURN_FALSE; } + RETURN_TRUE; } /* }}} */ @@ -2624,12 +2627,12 @@ static ZIPARCHIVE_METHOD(renameName) char *name, *new_name; size_t name_len, new_name_len; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &name_len, &new_name, &new_name_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (new_name_len < 1) { php_error_docref(NULL, E_NOTICE, "Empty string as new entry name"); RETURN_FALSE; @@ -2640,6 +2643,7 @@ static ZIPARCHIVE_METHOD(renameName) if (zip_file_rename(intern, sb.index, (const char *)new_name, 0)) { RETURN_FALSE; } + RETURN_TRUE; } /* }}} */ @@ -2652,12 +2656,12 @@ static ZIPARCHIVE_METHOD(unchangeIndex) zval *self = ZEND_THIS; zend_long index; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (index < 0) { RETURN_FALSE; } @@ -2680,12 +2684,12 @@ static ZIPARCHIVE_METHOD(unchangeName) char *name; size_t name_len; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &name_len) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (name_len < 1) { RETURN_FALSE; } @@ -2765,19 +2769,20 @@ static ZIPARCHIVE_METHOD(extractTo) RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (pathto_len < 1) { RETURN_FALSE; } if (php_stream_stat_path_ex(pathto, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) { - ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL); - if (!ret) { - RETURN_FALSE; - } + ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL); + if (!ret) { + RETURN_FALSE; + } } - ZIP_FROM_OBJECT(intern, self); - if (zval_files && (Z_TYPE_P(zval_files) != IS_NULL)) { + if (zval_files && Z_TYPE_P(zval_files) != IS_NULL) { uint32_t nelems, i; switch (Z_TYPE_P(zval_files)) { @@ -2805,10 +2810,9 @@ static ZIPARCHIVE_METHOD(extractTo) } } break; - case IS_LONG: default: - php_error_docref(NULL, E_WARNING, "Invalid argument, expect string or array of strings"); - break; + zend_argument_type_error(2, "must be of type array|string, %s given", zend_zval_type_name(zval_files)); + RETURN_THROWS(); } } else { /* Extract all files */ @@ -2847,17 +2851,21 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ int n = 0; - ZIP_FROM_OBJECT(intern, self); - if (type == 1) { if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|ll", &filename, &len, &flags) == FAILURE) { RETURN_THROWS(); } + + ZIP_FROM_OBJECT(intern, self); + PHP_ZIP_STAT_PATH(intern, ZSTR_VAL(filename), ZSTR_LEN(filename), flags, sb); } else { if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|ll", &index, &len, &flags) == FAILURE) { RETURN_THROWS(); } + + ZIP_FROM_OBJECT(intern, self); + PHP_ZIP_STAT_INDEX(intern, index, 0, sb); } @@ -2920,12 +2928,12 @@ static ZIPARCHIVE_METHOD(getStream) php_stream *stream; ze_zip_object *obj; - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "P", &filename) == FAILURE) { RETURN_THROWS(); } + ZIP_FROM_OBJECT(intern, self); + if (zip_stat(intern, ZSTR_VAL(filename), 0, &sb) != 0) { RETURN_FALSE; } @@ -2968,8 +2976,6 @@ static ZIPARCHIVE_METHOD(registerProgressCallback) RETURN_FALSE; } - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "dz", &rate, &callback) == FAILURE) { return; } @@ -2982,6 +2988,8 @@ static ZIPARCHIVE_METHOD(registerProgressCallback) RETURN_FALSE; } + ZIP_FROM_OBJECT(intern, self); + obj = Z_ZIP_P(self); /* free if called twice */ @@ -3026,12 +3034,12 @@ static ZIPARCHIVE_METHOD(registerCancelCallback) RETURN_FALSE; } - ZIP_FROM_OBJECT(intern, self); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback) == FAILURE) { return; } + ZIP_FROM_OBJECT(intern, self); + /* callable? */ if (!zend_is_callable(callback, 0, NULL)) { zend_string *callback_name = zend_get_callable_name(callback); diff --git a/ext/zip/php_zip.stub.php b/ext/zip/php_zip.stub.php index 101afcbe8ee4..e7aabe2c6c20 100644 --- a/ext/zip/php_zip.stub.php +++ b/ext/zip/php_zip.stub.php @@ -64,16 +64,16 @@ public function addEmptyDir(string $dirname, int $flags = 0) {} public function addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE) {} /** @return bool */ - public function addFile(string $filepath, string $entryname = UNKNOWN, int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) {} + public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) {} /** @return bool */ public function replaceFile(string $filepath, string $index, int $start = 0, int $length = 0, int $flags = 0) {} /** @return array|false */ - public function addGlob(string $pattern, int $flags = 0, $options = UNKNOWN) {} + public function addGlob(string $pattern, int $flags = 0, array $options = []) {} /** @return array|false */ - public function addPattern(string $pattern, string $path = UNKNOWN, $options = UNKNOWN) {} + public function addPattern(string $pattern, string $path = ".", array $options = []) {} /** @return bool */ public function renameIndex(int $index, string $new_name) {} @@ -138,7 +138,7 @@ public function unchangeIndex(int $index) {} public function unchangeName(string $name) {} /** @return bool */ - public function extractTo(string $pathto, $files = UNKNOWN) {} + public function extractTo(string $pathto, $files = null) {} /** @return string|false */ public function getFromName(string $entryname, int $len = 0, int $flags = 0) {} @@ -171,10 +171,10 @@ public function setCompressionIndex(int $index, int $method, int $compflags = 0) #ifdef HAVE_ENCRYPTION /** @return bool */ - public function setEncryptionName(string $name, int $method, string $password = UNKNOWN) {} + public function setEncryptionName(string $name, int $method, ?string $password = null) {} /** @return bool */ - public function setEncryptionIndex(int $index, int $method, string $password = UNKNOWN) {} + public function setEncryptionIndex(int $index, int $method, ?string $password = null) {} #endif #ifdef HAVE_PROGRESS_CALLBACK diff --git a/ext/zip/php_zip_arginfo.h b/ext/zip/php_zip_arginfo.h index ac392ef51744..31d816851880 100644 --- a/ext/zip/php_zip_arginfo.h +++ b/ext/zip/php_zip_arginfo.h @@ -68,7 +68,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addFile, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, filepath, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, entryname, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, entryname, IS_STRING, 0, "\"\"") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ZipArchive::FL_OVERWRITE") @@ -85,13 +85,13 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addGlob, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") - ZEND_ARG_INFO(0, options) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addPattern, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0) - ZEND_ARG_INFO(0, options) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 0, "\".\"") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_renameIndex, 0, 0, 2) @@ -174,7 +174,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_extractTo, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, pathto, IS_STRING, 0) - ZEND_ARG_INFO(0, files) + ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, files, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_getFromName, 0, 0, 1) @@ -245,7 +245,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setEncryptionName, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif @@ -253,7 +253,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setEncryptionIndex, 0, 0, 2) ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0) - ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null") ZEND_END_ARG_INFO() #endif