A data connection initialization code, I previously learned C #, is the constructor of the $dbo=null this can not understand, please advise.
I can not =null, directly with $dbo, I personally understand is $dbo=null this statement means that $dbo is not an object type, then why do you want to judge? $dbo =null This null value does not go inside the function?
protected function __construct ($dbo)
{
//...
}
Class db_connect{protected $db;p rotected function __construct ($dbo =null) {if (Is_object ($dbo)) {$this->db= $dbo;} else{$dsn = "mysql:host=". Db_host. "; Dbname= ". db_name;try {$this->db=new PDO ($DSN, db_user,db_pass);} catch (Exception $e) {die ($e->getmessage ());}}}}
Reply to discussion (solution)
function __construct ($dbo =null)
Indicates $dbo This parameter is default, because he has an initial value of NULL
If it is only
function __construct ($dbo)
Then $dbo this parameter must be passed in
Due to the default parameters,
New Db_connect ();
New Db_connect ($DB);
It's not going wrong.
C # supports overloading, so for this case you might be writing
Db_connect::__construct ($dbo) {}
Db_connect::__construct () {}
That's what I understand. and C # very different, Ah, C # in this parameter must be passed in, the mind is not the concept of ... So I can't understand it at all.
But object-oriented programming, overloading is a very important concept (method)