Bug #66966 [Opn]: __toString not call by http_build_query
Edit report at https://bugs.php.net/bug.php?id=66966&edit=1
ID: 66966
Updated by: cmb@php.net
Reported by: dev dot php at ange7 dot com
Summary: __toString not call by http_build_query
Status: Open
Type: Bug
Package: URL related
Operating System: Linux Debian Wheezy
PHP Version: 5.5.9
Block user comment: N
Private report: N
New Comment:
I can confirm the behavior: <http://3v4l.org/16dMa>.
However, I'm
not sure whether this qualifies as bug in PHP (it seems to be more
like a feature request).
Anyhow, you could simply cast the object to string manually, see
<http://3v4l.org/eMb8J>.
Previous Comments:
------------------------------------------------------------------------
[2014-07-28 07:39:35] martijn dot otto at copernica dot com
Is there any progress information available for this bug? It's pretty annoying since it means
you always have to roll your own alternative to http_build_query.
------------------------------------------------------------------------
[2014-06-24 15:07:09] dev dot php at ange7 dot com
Nobody has any interest about this bug...?
------------------------------------------------------------------------
[2014-03-27 12:40:37] dev dot php at ange7 dot com
same bug with PHP 5.4.4-14+deb7u8
------------------------------------------------------------------------
[2014-03-27 12:34:46] dev dot php at ange7 dot com
Description:
------------
When you call http_build_query() method with array which contain one object, http_build_query
don't call «__toString» method
Test script:
---------------
<?php
class foo {
public function __toString()
{
return "bar";
}
}
$params = array();
$params['a'] = 'b';
$params['foo'] = new foo();
$query = http_build_query($params);
var_dump($params, $query);
Expected result:
----------------
a=b&foo=bar
Actual result:
--------------
a=b
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66966&edit=1
Thread (6 messages)