0

I have a simple class... I need to update public $token if it is setted. My code is:

<?php
class Amazon {
    public $token = '';
    public function update($key = '', $value = '')
    {
        if(isset($this->"{$key}"))
        {
            $this->"{$key}" = $value;
        }
        return true;
    }
}

But I am getting this error: Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'

Aykhan Amiraslanli
  • 593
  • 2
  • 8
  • 22
  • 2
    `$this->{$key}`, not `$this->"{$key}"`.... and why not take a look at the magic `__set()` method? http://php.net/manual/en/language.oop5.overloading.php#object.set – Mark Baker Apr 30 '16 at 14:43

1 Answers1

2

Try it without the quotes. $this->{$key}

programmerKev
  • 399
  • 1
  • 3
  • 7