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