diff --git a/ext/standard/streamsfuncs.c b/ext/standard/streamsfuncs.c index d1ed12a78c3a..c4c5cb83f6cf 100644 --- a/ext/standard/streamsfuncs.c +++ b/ext/standard/streamsfuncs.c @@ -953,6 +953,7 @@ static zend_result parse_context_params(php_stream_context *context, HashTable * context->notifier->dtor = user_space_stream_notifier_dtor; } if (NULL != (tmp = zend_hash_str_find(params, "options", sizeof("options")-1))) { + ZVAL_DEREF(tmp); if (Z_TYPE_P(tmp) == IS_ARRAY) { return parse_context_options(context, Z_ARRVAL_P(tmp)); } else { diff --git a/ext/standard/tests/streams/stream_context_create_params_reference.phpt b/ext/standard/tests/streams/stream_context_create_params_reference.phpt new file mode 100644 index 000000000000..d7afdd3f6f66 --- /dev/null +++ b/ext/standard/tests/streams/stream_context_create_params_reference.phpt @@ -0,0 +1,48 @@ +--TEST-- +stream_context_create() and stream_context_set_params() accept an "options" element held by reference +--FILE-- + ['method' => 'HEAD']]; +$params = ['options' => &$options]; + +try { + $context = stream_context_create(null, $params); + var_dump(stream_context_get_options($context)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +$context = stream_context_create(); +try { + var_dump(stream_context_set_params($context, $params)); + var_dump(stream_context_get_options($context)); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +$invalid = 'not an array'; +try { + stream_context_create(null, ['options' => &$invalid]); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +array(1) { + ["http"]=> + array(1) { + ["method"]=> + string(4) "HEAD" + } +} +bool(true) +array(1) { + ["http"]=> + array(1) { + ["method"]=> + string(4) "HEAD" + } +} +TypeError: Invalid stream/context parameter