Skip to content

http_build_query() skips Stringable params #10229

Open
@procodix

Description

@procodix

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions