Cameron A. Ellis Cameron A. Ellis - 1 year ago 105
PHP Question

dynamic class property $$value in php

How can i reference a class property knowing only a string?

class Foo
public $bar;

public function TestFoobar()

public function foobar($string)
echo $this->$$string; //doesn't work

what is the correct way to eval the string?

Answer Source

You only need to use one $ when referencing an object's member variable using a string variable.

echo $this->$string;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download