Skip to content

Commit a542efd

Browse files
committed
Sync with EN documentation (http_build_query, php/doc-en@f72c6031)
Fixes #2789
1 parent 13bdd02 commit a542efd

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

reference/url/functions/http-build-query.xml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- EN-Revision: e80ef2394f0c64be66917a5d4335736ae05b774f Maintainer: yannick Status: ready -->
2+
<!-- EN-Revision: f72c6031982a6f8152ef351d20f8e0d90e8f1612 Maintainer: lacatoire Status: ready -->
33
<!-- Reviewed: no -->
44
<refentry xml:id="function.http-build-query" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
55
<refnamediv>
@@ -40,6 +40,14 @@
4040
Si <parameter>data</parameter> est un objet, alors seuls les
4141
attributs publics seront utilisés dans le résultat.
4242
</para>
43+
<note>
44+
<simpara>
45+
La méthode magique <link linkend="object.tostring">__toString()</link>
46+
n'est pas appelée lorsqu'un objet est évalué. Pour utiliser la
47+
représentation sous forme de chaîne d'un objet dans la chaîne de requête,
48+
l'objet doit être explicitement converti en chaîne.
49+
</simpara>
50+
</note>
4351
</listitem>
4452
</varlistentry>
4553
<varlistentry>
@@ -265,6 +273,44 @@ echo http_build_query($parent);
265273
<screen>
266274
<![CDATA[
267275
pub=publicParent&pub_bar%5Bpub%5D=publicChild
276+
]]>
277+
</screen>
278+
</example>
279+
280+
<example>
281+
<title>Utilisation de <function>http_build_query</function> avec des objets contenant
282+
<link linkend="object.tostring">__toString()</link>
283+
</title>
284+
<programlisting role="php">
285+
<![CDATA[
286+
<?php
287+
class Foo {
288+
public $publicProperty = 'visible';
289+
290+
public function __toString() {
291+
return "bar";
292+
}
293+
}
294+
295+
$params = array(
296+
'a' => 'b',
297+
'foo' => new Foo()
298+
);
299+
300+
// Sans conversion, http_build_query lit les propriétés publiques
301+
echo http_build_query($params) . "\n";
302+
303+
// Avec une conversion explicite, http_build_query utilise la sortie de __toString()
304+
$params['foo'] = (string) new Foo();
305+
echo http_build_query($params) . "\n";
306+
?>
307+
]]>
308+
</programlisting>
309+
&example.outputs;
310+
<screen>
311+
<![CDATA[
312+
a=b&foo%5BpublicProperty%5D=visible
313+
a=b&foo=bar
268314
]]>
269315
</screen>
270316
</example>

0 commit comments

Comments
 (0)