Skip to content

Stdlib: http_build_query() — null arg_separator + encoding_type named args (ext/standard/http.c, php-src-strict) #6092

Description

@PurHur

Category

stdlib

Problem

Zend http_build_query() accepts:

  • $arg_separator = null — use & (PHP 7.4+)
  • $encoding_type — PHP_QUERY_RFC1738 (default) or PHP_QUERY_RFC3986 (spaces → %20, not +)
  • Named parameters — e.g. http_build_query($data, arg_separator: '&', encoding_type: PHP_QUERY_RFC3986)

This compiler rejects null separators, named-arg calls, and RFC3986 encoding:

Call Zend VM today
http_build_query(['a'=>'b c'], '', null, PHP_QUERY_RFC3986) a=b%20c LogicException: argument #3 must be a string
http_build_query(['a'=>'b c'], arg_separator: '&', encoding_type: PHP_QUERY_RFC3986) a=b%20c compile error: Too many arguments
http_build_query(['a'=>'b c'], encoding_type: PHP_QUERY_RFC3986) a=b%20c not supported

Distinct from #4272 (object/bool value encoding) and #5654 (backed enum case values).

php-src reference

  • php/php-src ext/standard/http.c — PHP_FUNCTION(http_build_query), php_url_encode_hash_ex
  • PHP_QUERY_RFC1738 / PHP_QUERY_RFC3986 constants in ext/standard/basic_functions.c

Repro

<?php
echo http_build_query(['a' => 'b c'], '', null, PHP_QUERY_RFC3986), "\n";
echo http_build_query(['a' => 'b c'], arg_separator: '&', encoding_type: PHP_QUERY_RFC3986), "\n";
./script/docker-exec.sh -- bash -lc '
php /tmp/repro/hbq.php
php bin/vm.php /tmp/repro/hbq.php
'

(Write /tmp/repro/hbq.php with the snippet above.)

Scope (PHP-in-PHP first)

Path Work
ext/standard/http_build_query.php Accept null arg #3 → default &; honor arg #4 / named encoding_type
ext/standard/VmHttpBuildQuery.php RFC3986 vs RFC1738 space encoding (%20 vs +)
ext/standard/Module.php Register PHP_QUERY_RFC1738 / PHP_QUERY_RFC3986 if missing
lib/JIT/Builtin/ Mirror encoding flag in JitHttpBuildQuery / __compiler_http_build_query
test/compliance/cases/stdlib/http_build_query_encoding.phpt null separator + RFC3986 + named args

Current VM code throws when arg #3 is not TYPE_STRING (ext/standard/http_build_query.php).

Done when

  • Repro lines print a=b%20c on VM (match Zend)
  • null $arg_separator coerces to &
  • Named-parameter calls compile and run
  • Invalid encoding_type → ValueError like Zend
  • ./script/ci-fast.sh --filter http_build_query_encoding green

php-src-strict: enum case operands in data array covered by #5654; this issue is separator/encoding signature parity only.

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