In my PHP class I have
public $a;
public $b;
public $c;
public $d;
and I set there values in the construct.
I am now attempting to write a update function, and i’m trying to check if they are updating, say $a, to be the same as it is.
function update($what, $to) {
if ($to == $this->what) return false;
...
}
$updated = $instance->update($a, "Foobar");
if ($updated) echo "Updated";
else echo "You didn't change the value";
but since I know this line
if ($to == $this->what) return false;
is invalid, i’m seeking a new way to write it.
Ideas?
Thanks in advance
The solution to your dilemma are variable variables. Your update function must assign it like this:
The if-check would be correspondingly:
And you cannot actually invoke the update() method with a variable
$a. You must give it a variable name as string: