Short: Yes, this will close the MySQLi connection.
Why: It is important to note that, in PHP, Objects are always passed by reference. That is to say, the variable is actually a link to memory space that represents that object, and wherever the value of that variable goes, it will always point to the same space in memory, and therefore, the same object.
Example:
The following illustrates the difference between passing by copy, pass by reference, and how objects work:
function copy_increment($int) {
$int++;
}
function reference_increment(&$int) {
$int++;
}
function object_increment($object) {
$object->int++;
}
function maybe_destroy($object) {
unset($object);
}
$object = new StdClass();
$object->int = 1;
$int_val = 1;
var_dump($int_val); // 1
copy_increment($int_val); // Not passed by reference
var_dump($int_val); // 1
reference_increment($int_val); // Passed by reference
var_dump($int_val); // 2
var_dump($object); // int = 1
object_increment($object); // Always passed by reference
var_dump($object); // int = 2
// But here you can see that the parameters are
// still copies, but copies of the pointer and
// un-setting only effects the current scope.
maybe_destroy($object);
var_dump($object); // int = 2
You can see this in action here. What does this mean in your case? It means that, yes, when you pass the MySQLi connection and store it, and then close it, it will invariably close all copies of that object.
There is a catch here in that you can clone objects, but MySQLi is what they call an "un-clone-able object," and it will kill your app if you try... :-(
TO NOTE: The MySQLi connection does not "need" to be explicitly closed, and the connection will terminate when the object is destroyed (at the end of the application or during Garbage Collection), so you should never have to explicitly call close on it.
Another option would be to have a factory class or function that builds the connection on demand. Pass this object to the constructor, and store the unique connection on this object. I can not think immediately off the top of my head why this would be useful, but it would be fairly easy to set up, and would allow you to close connections all day long. ;-)
Really though, you don't need to close it manually, particularly if you are just starting out.
$this -> var -> close();actually closing my mysqli connection?$varobject attribute has your$mysqliobject, passed in constructor, and you're callingclose()on it, and$mysqli->close()closes your connection.