Pass object as parameter in function not working
<p>This seems extremely easy but for the life of me can't figure out why this is not working.  I am trying to simply pass an object into a function but I get this error:</p>

<p>Catchable fatal error: Argument 3 passed to write_query() must be an instance of   mysqli, null given, called in C:\xampp\htdocs\CSP\login\login.php on line 28 and defined in C:\xampp\htdocs\CSP\php_scripts\login_script.php on line 40</p>

<p>These are my functions definitions:</p>

<pre><code>function conn_database()
    {
        if (!empty($_POST['userid']) &amp;&amp; !empty($_POST['password']))
        {
            $conn = new mysqli('localhost', 'root', '', 'csp');

            if (mysqli_connect_errno()) 
            {
                echo 'Connection to database failed:'.mysqli_connect_error();
                exit();
            }
            return $conn;
        }

    }


function write_query($userid, $password, mysqli $conn)
    {
        $query = 'select * from authorized_users '
        ."where userid= '$userid'"
        ."and password_id='$password'";
        $result = $conn-&gt;query($query);
        return $result;
    }
</code></pre>

<p>I am calling them like this:</p>

<pre><code>$conn = conn_database();
$result = write_query($userid, $password, $conn);
</code></pre>

<p>I'm type hinting in the definition of the write_query() but from what I understand from the error, my third argument is not considered an instance of mysqli.  (I am aware I should be salting the password and all, I'm just trying to get this to work first).  Any suggestions would be appreciated </p>
