[php-src] Issue #10229: http_build_query() skips Stringable params

From: Date: Thu, 05 Jan 2023 12:36:47 +0000
Subject: [php-src] Issue #10229: http_build_query() skips Stringable params
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243345@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10229
Author: procodix

### Description

The following code:

```php
<?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


Thread (1 message)

  • procodix
« previous php.bugs (#243345) next »