php / php/php-src

http_build_query() skips Stringable params

Open
#10,229 0 comments 1 reaction 1 assignee View on GitHub

@Girgias is already working on this.

Since Jan 5, 2023.

Bug Extension: standard Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php 

$params = [
    'param1' => 1,
    'param2' => new Class {
        public function __toString():string {return 'test';}
    }
];

echo http_build_query($params);

foreach ($params as $k => &$v) $params[$k] = (string) $v;

echo http_build_query($params);

Resulted in this output:

param1=1

But I expected this output instead:

param1=1&param2=test

... as __toString() should have been implicitly called on the object. The ugly manual conversion shouldn't be necessary.

PHP Version

PHP 8.1

Operating System

Any

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.