http_build_query() skips Stringable params
Open
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¶m2=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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.