Never follow rules blindly. Aways understand the reasons behind best practices and you will then implicitly understand the variations and exceptions.McGruff wrote:Never.Shears wrote:When should I use $object->variableAlways.Shears wrote: and when should I use $object->get_variable()?
sets and gets?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: sets and gets?
(#10850)
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Ancient news. One should use PDO!First, I'd use mysqli - but what php version are you using?
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
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.ole wrote:trackback:Nope privatestereofrog wrote:in ruby all object fields are protected by defaultjust read it.
-
Jeroen Oosterlaar
- Forum Commoner
- Posts: 37
- Joined: Sun Nov 06, 2005 4:12 pm
Re: sets and gets?
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.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.