FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » OOP, classes and databases
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: OOP, classes and databases [message #169418 is a reply to message #169414] Sat, 11 September 2010 13:45 Go to previous messageGo to previous message
aaaa is currently offline  aaaa
Messages: 7
Registered: September 2010
Karma:
Junior Member
>> - __get and __set is the way for getting and setting properties
> No. Usually properties are private and you write getFoo() and setFoo(
> $value ) methods to retrieve and set their values in a controlled way
> (allowing to validate the value to be set, for example). There may be
> circumstances where it is okay to allow anyone unrestricted access to a
> property. In this case, you can make the property public and don't need
> __get/__set. If you want to control access to a property, but still allow
> the simpler syntax $object->foo = 42, then you can use __get/__set. Also,
> if you want to allow public read-only access to a private property, you
> can use __get to achieve that.

Methods __get and __set are OK, if you use them like this:

public function __set($var, $val)
{
switch ($var)
{
case 'name1' : //validation here
break;
case 'name2' :
case 'name3' : //validation here
break;
}
$this->variables[$var] = $val;
}

--
A
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Best PHP way to connect to a DB across multiple pages ?
Next Topic: When do I use {}?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 15:50:34 GMT 2024

Total time taken to generate the page: 0.04026 seconds