Repository navigation
Closed
Labels
area:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web apps
Description
Category
stdlib
Problem
Calling stream_context_create(['http' => ['timeout' => 5]]) under the VM aborts with Refcount is > 1, but was asserted to be 1 instead of returning a stream-context resource like Zend. This blocks HTTP/stream wrappers with custom context (bootstrap probes, file_get_contents with context).
Distinct from #4627 (TypeError for non-array options) — operand type is valid but runtime crashes.
php-src reference
- php/php-src
ext/standard/streams.c—php_stream_context_create(),php_stream_context_alloc() - Returns
php_stream_contextwrapped asstream-contextresource (zend_listentry)
Repro (today)
Save as repro_stream_context_create.php:
<?php
$ctx = stream_context_create(['http' => ['timeout' => 5]]);
var_export(is_resource($ctx));
echo "\n";
var_export(get_resource_type($ctx));
echo "\n";./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro_stream_context_create.php
php bin/vm.php repro_stream_context_create.php
'| Runtime | Result |
|---|---|
| Zend | true, 'stream-context' |
| VM (2026-06-03) | Fatal: Refcount is > 1, but was asserted to be 1 |
Scope (this repo)
| Area | Files | Notes |
|---|---|---|
| VM builtin | ext/standard/stream_context_create.php |
Today returns array via VmStreamContext::create() — align with Zend resource model |
| Stream layer | ext/standard/VmStreamContext.php, VmFs.php |
Fix refcount when nesting options arrays (likely copy-by-ref from VmHttpBuildQuery::export) |
| Registration | ext/standard/Module.php |
|
| Tests | test/compliance/cases/stdlib/stream_context_create.phpt (extend existing JIT cases) |
Investigation hint: trace VmStreamContext::create($options, $params) — ensure nested wrapper arrays are copied, not aliased refcount>1 Variable graphs passed into resource boxing.
Done when
- Repro returns
stream-contextresource (or documented interim type if phased — must matchget_resource_type()Zend strings) - No refcount assertion fatal on nested
['http'=>['timeout'=>N]]options - Options preserved for Stdlib: stream_context_set_option / get_options / get_params / set_default (ext/standard/streams.c parity) #3448
stream_context_set_option()follow-ups -
./script/ci-fast.sh --filter stream_context_creategreen
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter stream_context_create'Links
- Stdlib: stream_context_create() — TypeError for non-array options (ext/standard/streams.c parity) #4627, Stdlib: stream_context_set_option / get_options / get_params / set_default (ext/standard/streams.c parity) #3448, Stdlib: stream_context_create() — VM + LLVM JIT/AOT #1377, Stdlib: stream_get_meta_data / stream_set_blocking — stream introspection (ext/standard/streams.c parity) #3237, Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492
Metadata
Metadata
Assignees
Labels
area:vmVirtual machineVirtual machineenhancementNew feature or requestNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimSpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web appsPhase 4 – stdlib for web apps
Activity
PurHur commentedon Jun 15, 2026
claim: PHP Runtime → PHP — starting this run (#4738: stream_context_create nested options array + resource return).
Fix inline nested array literals as function call arguments (#4738) (#…
PurHur commentedon Jun 15, 2026
Merged via #8646.
Fix:
lib/Compiler.phpmatchInlineCallArgProducer()— map nestedExpr_Arrayproducer chains to the correct inline literal call operand (php-cfg emits one producer per nesting level; disconnected temps brokestream_context_create(['http'=>['timeout'=>5]])).Verification:
Follow-up (separate):
stream_context_set_options/set_paramsPHPTs still red when callee is nested insidevar_export(...)(inner FUNCCALL return slot); assign-form$ok = stream_context_set_options(...)works on branch.