sets and gets?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: sets and gets?

Post 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.
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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]
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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. ;)
Jeroen Oosterlaar
Forum Commoner
Posts: 37
Joined: Sun Nov 06, 2005 4:12 pm

Re: sets and gets?

Post 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.
Post Reply