Page 2 of 2

Re: sets and gets?

Posted: Thu Jul 26, 2007 9:54 pm
by Christopher
McGruff wrote:
Shears wrote:When should I use $object->variable
Never.
Shears wrote: and when should I use $object->get_variable()?
Always.
Never follow rules blindly. Aways understand the reasons behind best practices and you will then implicitly understand the variations and exceptions.

Posted: Fri Jul 27, 2007 2:47 am
by Maugrim_The_Reaper
First, I'd use mysqli - but what php version are you using?
Ancient news. One should use PDO! ;). If you're really cool, use mysqlnd.[/url]

Posted: Fri Jul 27, 2007 3:01 am
by stereofrog
ole wrote:trackback:
stereofrog wrote:in ruby all object fields are protected by default
Nope private :D just read it.
ruby uses object-based visibility rules for instance variables, not class based like java, therefore both "private" and "protected" don't make much sense in ruby. I only used the term "protected" to make things easier to understand for you. ;)

Re: sets and gets?

Posted: Fri Aug 03, 2007 4:02 am
by Jeroen Oosterlaar
Shears wrote:However, when I look at various classes, there seems like a 99.98% chance there will be used in some places $object->variable to get values.
Maybe that is because the code you are regarding to is written for a PHP version lower than 5, or written to be compatible with a PHP version lower than 5? Before PHP 5 you could not declare the scope (private, protected, public) of a class variable. In that case it doesn't make sense to write getters and setters. The PHPMailer module is an example of this. It offers getters and setters, but you can just as well approach the properties directly.