drag0n;10890785 wrote:hi:
i have just started to use oop in php... and i have a few questions.
what is the difference between "private function _construct()" and "private function className()"? Can I use either one to create the constructor?
Functionally there is no difference that I know of. Practically speaking, by using __construct() you do not need to worry about renaming the constructor method should you decide at some point to rename the class.
i have been using a mysql wrapper class for all my mysql operations; and one of the functions of this class is to open mysql connections. alot of my functions within my user class deals with the db. I am wondering which would be more effective: putting the "$db = new MySQL; $db->Open();" only in the constructor so its initiated for the entire class or initiating it each time in each function that needs db access?
Unless you have some specific reason for using multiple connections, I would recommend just using a single, initial connection in order to avoid unnecessary processing.
Also; a newb question... why must we always use "==" when checking for values in if statements? In most other languages I can use a single "=" when checking for boolean values; but in PHP you have to use == for everything. Does that mean we dont ever use a single = when checking variables?
Thanks
"=" is an assignment operator, "==" is a comparison operator; therefore they have very different purposes and uses. By not overloading the "=" operator with both functions, it allows you to use both within a larger expression without any ambiguity, e.g.:
if(($count = $count + 1) == 100)
{
break;
}
(That's a somewhat silly example, but it's the first thing I thought of.)