Skip to content

Commit 7bc0dd2

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Add missing error condition to stream_context_set_option()
2 parents f7b1238 + 1b01bf3 commit 7bc0dd2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

ext/standard/streamsfuncs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,10 @@ PHP_FUNCTION(stream_context_set_option)
10291029
zend_argument_value_error(3, "cannot be null when argument #2 ($wrapper_or_options) is a string");
10301030
RETURN_THROWS();
10311031
}
1032+
if (!zvalue) {
1033+
zend_argument_value_error(4, "must be provided when argument #2 ($wrapper_or_options) is a string");
1034+
RETURN_THROWS();
1035+
}
10321036

10331037
RETURN_BOOL(php_stream_context_set_option(context, ZSTR_VAL(wrappername), optionname, zvalue) == SUCCESS);
10341038
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
stream_context_set_option() error conditions
3+
--FILE--
4+
<?php
5+
6+
$ctx = stream_context_create();
7+
try {
8+
stream_context_set_option($ctx, [], "x");
9+
} catch (Error $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
try {
13+
stream_context_set_option($ctx, [], null, "x");
14+
} catch (Error $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
try {
18+
stream_context_set_option($ctx, "x");
19+
} catch (Error $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
try {
23+
stream_context_set_option($ctx, "x", "y");
24+
} catch (Error $e) {
25+
echo $e->getMessage(), "\n";
26+
}
27+
28+
?>
29+
--EXPECT--
30+
stream_context_set_option(): Argument #3 ($option_name) must be null when argument #2 ($wrapper_or_options) is an array
31+
stream_context_set_option(): Argument #4 ($value) cannot be provided when argument #2 ($wrapper_or_options) is an array
32+
stream_context_set_option(): Argument #3 ($option_name) cannot be null when argument #2 ($wrapper_or_options) is a string
33+
stream_context_set_option(): Argument #4 ($value) must be provided when argument #2 ($wrapper_or_options) is a string

0 commit comments

Comments
 (0)