1--TEST--
2mysqli_stmt_bind_param() - checking whether the parameters are modified (bug#44390)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require('table.inc');
12	$link->set_charset('latin1');
13
14	class foo {
15	  // @var $bar string
16	  public $bar;
17	}
18
19	$foo = new foo;
20	$foo->bar = "фубар";
21
22	echo "Test 1:\n";
23	$stmt = $link->prepare("SELECT ? FOO");
24	var_dump($foo); // here you can see the bar member var being a string
25	$stmt->bind_param("s", $foo->bar);
26	var_dump($foo); // this will show $foo->bar being a reference string
27	$stmt->bind_result($one);
28	$stmt->execute();
29	$stmt->fetch();
30	$stmt->free_result();
31	echo("$one\n\n");
32
33	// it is getting worse. Binding the same var twice with different
34	// types you can get unexpected results (e.g. binary trash for the
35	// string and misc data for the integer. See next 2 tests.
36
37	echo "Test 2:\n";
38	$stmt = $link->prepare("SELECT ? FOO, ? BAR");
39	var_dump($foo);
40	$stmt->bind_param("si", $foo->bar, $foo->bar);
41	echo "---\n";
42	var_dump($foo);
43	echo "---\n";
44	$stmt->execute();
45	var_dump($foo);
46	echo "---\n";
47	$stmt->bind_result($one, $two);
48	$stmt->fetch();
49	$stmt->free_result();
50	echo("$one - $two\n\n");
51
52
53	echo "Test 3:\n";
54	$stmt = $link->prepare("SELECT ? FOO, ? BAR");
55	var_dump($foo);
56	$stmt->bind_param("is", $foo->bar, $foo->bar);
57	var_dump($foo);
58	$stmt->bind_result($one, $two);
59	$stmt->execute();
60	$stmt->fetch();
61	$stmt->free_result();
62	echo("$one - $two\n\n");
63	echo "done!";
64?>
65--CLEAN--
66<?php
67	require_once("clean_table.inc");
68?>
69--EXPECTF--
70Test 1:
71object(foo)#%d (1) {
72  [%u|b%"bar"]=>
73  %unicode|string%(%d) "фубар"
74}
75object(foo)#%d (1) {
76  [%u|b%"bar"]=>
77  &%unicode|string%(%d) "фубар"
78}
79фубар
80
81Test 2:
82object(foo)#%d (1) {
83  [%u|b%"bar"]=>
84  %unicode|string%(%d) "фубар"
85}
86---
87object(foo)#%d (1) {
88  [%u|b%"bar"]=>
89  &%unicode|string%(%d) "фубар"
90}
91---
92object(foo)#%d (1) {
93  [%u|b%"bar"]=>
94  &%unicode|string%(%d) "фубар"
95}
96---
97фубар - 0
98
99Test 3:
100object(foo)#%d (1) {
101  [%u|b%"bar"]=>
102  %unicode|string%(%d) "фубар"
103}
104object(foo)#%d (1) {
105  [%u|b%"bar"]=>
106  &%unicode|string%(%d) "фубар"
107}
1080 - фубар
109
110done!