php / php/php-src

http_build_query() skips Stringable params

Aperta
#10,229 0 commenti 1 reazione 1 assegnatario Vedi su GitHub

@Girgias ci sta già lavorando.

Dal 5/1/2023.

  • #10235 di @Girgias — aperta
Bug Extension: standard Status: Verified
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.