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