1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Make the return type of some stream context related functions true (#12720)

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
This commit is contained in:
Máté Kocsis
2023-11-19 20:36:42 +01:00
committed by GitHub
parent c15db2250d
commit ed6e289c31
4 changed files with 58 additions and 18 deletions

View File

@@ -3320,7 +3320,7 @@ function stream_select(?array &$read, ?array &$write, ?array &$except, ?int $sec
function stream_context_create(?array $options = null, ?array $params = null) {}
/** @param resource $context */
function stream_context_set_params($context, array $params): bool {}
function stream_context_set_params($context, array $params): true {}
/**
* @param resource $context
@@ -3330,10 +3330,10 @@ function stream_context_set_params($context, array $params): bool {}
function stream_context_get_params($context): array {}
/** @param resource $context */
function stream_context_set_option($context, array|string $wrapper_or_options, ?string $option_name = null, mixed $value = UNKNOWN): bool {}
function stream_context_set_option($context, array|string $wrapper_or_options, ?string $option_name = null, mixed $value = UNKNOWN): true {}
/** @param resource $context */
function stream_context_set_options($context, array $options): bool {}
function stream_context_set_options($context, array $options): true {}
/**
* @param resource $stream_or_context

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: ef14c8ce17c75ee21befd09477934f005eabb1ed */
* Stub hash: c9edbe45bb7a2b00b413fb3c56683bb8377a725f */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -1826,7 +1826,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_stream_context_create, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, params, IS_ARRAY, 1, "null")
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_params, 0, 2, _IS_BOOL, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_params, 0, 2, IS_TRUE, 0)
ZEND_ARG_INFO(0, context)
ZEND_ARG_TYPE_INFO(0, params, IS_ARRAY, 0)
ZEND_END_ARG_INFO()
@@ -1835,14 +1835,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_get_params, 0, 1,
ZEND_ARG_INFO(0, context)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_option, 0, 2, _IS_BOOL, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_option, 0, 2, IS_TRUE, 0)
ZEND_ARG_INFO(0, context)
ZEND_ARG_TYPE_MASK(0, wrapper_or_options, MAY_BE_ARRAY|MAY_BE_STRING, NULL)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, option_name, IS_STRING, 1, "null")
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_options, 0, 2, _IS_BOOL, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stream_context_set_options, 0, 2, IS_TRUE, 0)
ZEND_ARG_INFO(0, context)
ZEND_ARG_TYPE_INFO(0, options, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

View File

@@ -908,11 +908,10 @@ static void user_space_stream_notifier_dtor(php_stream_notifier *notifier)
}
}
static int parse_context_options(php_stream_context *context, HashTable *options)
static zend_result parse_context_options(php_stream_context *context, HashTable *options)
{
zval *wval, *oval;
zend_string *wkey, *okey;
int ret = SUCCESS;
ZEND_HASH_FOREACH_STR_KEY_VAL(options, wkey, wval) {
ZVAL_DEREF(wval);
@@ -930,12 +929,11 @@ static int parse_context_options(php_stream_context *context, HashTable *options
}
} ZEND_HASH_FOREACH_END();
return ret;
return SUCCESS;
}
static int parse_context_params(php_stream_context *context, HashTable *params)
static zend_result parse_context_params(php_stream_context *context, HashTable *params)
{
int ret = SUCCESS;
zval *tmp;
if (NULL != (tmp = zend_hash_str_find(params, "notification", sizeof("notification")-1))) {
@@ -959,7 +957,7 @@ static int parse_context_params(php_stream_context *context, HashTable *params)
}
}
return ret;
return SUCCESS;
}
/* given a zval which is either a stream or a context, return the underlying
@@ -1048,7 +1046,11 @@ PHP_FUNCTION(stream_context_set_option)
RETURN_THROWS();
}
RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
if (parse_context_options(context, options) == FAILURE) {
RETURN_THROWS();
}
RETURN_TRUE;
} else {
if (!optionname) {
zend_argument_value_error(3, "cannot be null when argument #2 ($wrapper_or_options) is a string");
@@ -1081,7 +1083,11 @@ PHP_FUNCTION(stream_context_set_options)
RETURN_THROWS();
}
RETURN_BOOL(parse_context_options(context, options) == SUCCESS);
if (parse_context_options(context, options) == FAILURE) {
RETURN_THROWS();
}
RETURN_TRUE;
}
/* {{{ Set parameters for a file context */
@@ -1102,7 +1108,11 @@ PHP_FUNCTION(stream_context_set_params)
RETURN_THROWS();
}
RETVAL_BOOL(parse_context_params(context, params) == SUCCESS);
if (parse_context_params(context, params) == FAILURE) {
RETURN_THROWS();
}
RETURN_TRUE;
}
/* }}} */
@@ -1197,11 +1207,15 @@ PHP_FUNCTION(stream_context_create)
context = php_stream_context_alloc();
if (options) {
parse_context_options(context, options);
if (parse_context_options(context, options) == FAILURE) {
RETURN_THROWS();
}
}
if (params) {
parse_context_params(context, params);
if (parse_context_params(context, params) == FAILURE) {
RETURN_THROWS();
}
}
RETURN_RES(context->res);

View File

@@ -0,0 +1,26 @@
--TEST--
Test the error cases of stream_context_create()
--FILE--
<?php
try {
stream_context_create(['ssl' => "abc"]);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
stream_context_create(['ssl' => ['verify_peer'=> false]], ["options" => ['ssl' => "abc"]]);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
try {
stream_context_create(['ssl' => ['verify_peer'=> false]], ["options" => false]);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECT--
Options should have the form ["wrappername"]["optionname"] = $value
Options should have the form ["wrappername"]["optionname"] = $value
Invalid stream/context parameter