/usr/share/php/tests/PHP_Compat/tests/function/http_build_query.phpt is in php-compat 1.6.0a3-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | --TEST--
Function -- http_build_query
--FILE--
<?php
require_once 'PHP/Compat/Function/http_build_query.php';
// With an empty separator (doing this after giving it a value with ini_set has no effect)
ini_set('arg_separator.output', '');
$data = array('foo', 'bar', 'baz', 'boom', 'cow' => 'milk', 'php' =>'hypertext processor');
echo php_compat_http_build_query($data, 'flags_'), "\n";
// Ini
ini_set('arg_separator.output', '*');
// Simple
$data = array('foo'=>'bar',
'baz'=>'boom',
'cow'=>'milk',
'php'=>'hypertext processor');
echo php_compat_http_build_query($data), "\n";
// With an object
class myClass {
var $foo;
var $baz;
function myClass()
{
$this->foo = 'bar';
$this->baz = 'boom';
}
}
$data = new myClass();
echo php_compat_http_build_query($data), "\n";
// With numerically indexed elements
$data = array('foo', 'bar', 'baz', 'boom', 'cow' => 'milk', 'php' =>'hypertext processor');
echo php_compat_http_build_query($data), "\n";
echo php_compat_http_build_query($data, 'myvar_'), "\n";
// With a complex array
$data = array('user' => array(
'name' => 'Bob Smith',
'age' => 47,
'sex' => 'M',
'dob' => '5/12/1956'),
'pastimes' => array(
'golf',
'opera',
'poker',
'rap'),
'children' => array(
'bobby' => array(
'age' => 12,
'sex' => 'M'),
'sally' => array(
'age' => 8,
'sex'=>'F')),
'CEO');
echo php_compat_http_build_query($data, 'flags_'), "\n";
// With a nested object
$data = array('foo' => new myClass());
echo php_compat_http_build_query($data, 'flags_'), "\n";
// With a key which evaluates to false
$data = array('' => array('hello world'), 'foo' => 'bar');
echo php_compat_http_build_query($data, 'flags_'), "\n";
// With a separator which evaluates to false
ini_set('arg_separator.output', '0');
echo php_compat_http_build_query($data, 'flags_'), "\n";
// With a resource
$data = array('foo' => null, 'bar' => fopen('php://input', 'r'));
var_dump(php_compat_http_build_query($data, 'flags_'));
// With a null value
$data = array('foo' => null, 'bar' => 1);
echo php_compat_http_build_query($data, 'flags_');
?>
--EXPECT--
flags_0=foo&flags_1=bar&flags_2=baz&flags_3=boom&cow=milk&php=hypertext+processor
foo=bar*baz=boom*cow=milk*php=hypertext+processor
foo=bar*baz=boom
0=foo*1=bar*2=baz*3=boom*cow=milk*php=hypertext+processor
myvar_0=foo*myvar_1=bar*myvar_2=baz*myvar_3=boom*cow=milk*php=hypertext+processor
user[name]=Bob+Smith*user[age]=47*user[sex]=M*user[dob]=5%2F12%2F1956*pastimes[0]=golf*pastimes[1]=opera*pastimes[2]=poker*pastimes[3]=rap*children[bobby][age]=12*children[bobby][sex]=M*children[sally][age]=8*children[sally][sex]=F*flags_0=CEO
foo[foo]=bar*foo[baz]=boom
[0]=hello+world*foo=bar
[0]=hello+world0foo=bar
NULL
bar=1
|