Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.