Skip to content

Fix UNKNOWN default values - part 3 #5516

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ext/spl/php_spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ext/spl/php_spl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
6 changes: 3 additions & 3 deletions ext/spl/php_spl_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ 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)
ZEND_ARG_INFO(0, class_name)
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()
Expand Down
4 changes: 2 additions & 2 deletions ext/sqlite3/sqlite3.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
4 changes: 2 additions & 2 deletions ext/sqlite3/sqlite3_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ext/xml/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions ext/xml/xml.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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 {}

Expand Down
6 changes: 3 additions & 3 deletions ext/xml/xml_arginfo.h
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ext/xmlreader/php_xmlreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/xmlreader/php_xmlreader.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
2 changes: 1 addition & 1 deletion ext/xmlreader/php_xmlreader_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ext/xsl/php_xsl.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
2 changes: 1 addition & 1 deletion ext/xsl/php_xsl_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 15 additions & 13 deletions ext/xsl/xsltprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Expand Down
Loading