Jump to content

best way to update class variables


ober

Recommended Posts

I am making a new product display class and I have all kinds of settings that are seperate variables within the class.  Is there an easy way to update these values without creating a ton of small functions like this:
[code]
<?php
function update_headerbgcolor($color)
{
      this->headerbgcolor = $color;
}
?>[/code]

Any help appreciated.
Link to comment
https://forums.phpfreaks.com/topic/22404-best-way-to-update-class-variables/
Share on other sites

With PHP4 you can just set with
[code]
$obj->var = $value.[/code]

Same goes for PHP5 public variables

For PHP5 private vars you can define a "magic function"
[code]
function __set ($var , $value) {
    $this->$var = $value;
}[/code]

which will then allow
[code]$obj->privateVar = $value;[/code]

hth
Eh... I'm stuck with PHP4 for this client.  I think I'll go with the first method, but I hadn't thought of passing the property and the value... the client will be updating these, so I'm trying to keep it as simple as possible.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.