Skip to content

Stdlib: parse_str() — second argument must accept uninitialized by-ref $result (ext/standard/basic_functions.c) #4737

Description

@PurHur

Category

stdlib · php-src-strict · spec refresh 2026-06-20

Problem

Two gaps in parse_str($encoded, $result) vs Zend:

1. Uninitialized by-ref $result (original scope)

Zend accepts an uninitialized variable passed by reference, allocates/populates the array. VM requires $result to already be an array (LogicException: argument #2 must be an array).

2. Return value — PHP 8+ void return (added 2026-06-20)

Since PHP 8.0, parse_str() returns null (void). VM returns true (ext/standard/parse_str.php sets $frame->returnVar->bool(true)).

Verified:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "parse_str(\"a=1\", \$out); var_export(\$out);"
php bin/vm.php -r "parse_str(\"a=1\", \$out); var_export(\$out);"
'
Call Zend VM today
parse_str('a=1', $out); var_export($out); array('a'=>'1') same array ✓
Return value of parse_str(...) null true

Distinct from #4050 (one-arg form) and #4219 (third-arg prefix).

php-src reference

  • php/php-src ext/standard/basic_functions.cPHP_FUNCTION(parse_str) / php_parse_str()
  • By-ref $result may be undefined; Zend creates the array in place
  • PHP 8+: function return type void (returns null in userland)

Repro

By-ref uninitialized:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parse_str_byref.php 2>&1
php bin/vm.php test/repro-maintainer/parse_str_byref.php 2>&1
'
Call Zend PHP 8.x VM today
parse_str('a=1&b=2', $result) (uninit $result) populated array LogicException

Return value:

<?php
declare(strict_types=1);
$out = [];
var_export(parse_str('a=1', $out));
echo "\n";
var_export($out);
echo "\n";

Scope (this repo)

Area Files
VM ext/standard/parse_str.php, VmParseStr.php — void return + uninit by-ref
JIT JitParseStr.php — write through by-ref slot when unset; no bool return
Tests test/compliance/cases/stdlib/parse_str_byref.phpt, parse_str_return_null.phpt

PHP-in-PHP: #9295 routes JIT through VmHttp — VM semantics first.

Done when

  • Uninitialized / non-array by-ref target replaced with parsed array (Zend semantics)
  • parse_str() return is null, not true
  • Existing array target merged/replaced per php-src rules
  • JIT/AOT match VM
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter parse_str' green

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions