I’m just new in learning OOP. I’ve read many articles so far and tried some tutorials. I just wonder why when declaring parameter on a constructor some values should be nulled.
function __construct($hostname = NULL, $username = NULL, $password = NULL, $database = NULL)
{
$this->hostname = !empty($hostname) ? $hostname : "";
$this->username = !empty($username) ? $username : "";
$this->password = !empty($password) ? $password : "";
$this->database = !empty($database) ? $database : "";
}
like this. I really want know.
Keeping argument as NULL would make the function run even if all the parameters are not passed during function call.
For example, if a function expects 3 arguments and you supplied only 2 and in function definition the third parameter is not assigned as NULL, the function will throw an error.