I am trying to set a variable of $tester that can be used in multiple functions in MyClass.
I have set the variable and added a function on __construct()
but I am getting an undefined variable notice when I try to echo it out - why is this?
class MyClass {
public $tester;
public function __construct() {
add_action( 'init', array( &$this, 'variables' ) );
add_action( 'init', array( &$this, 'do_stuff' ) );
}
public function variables() {
$tester = get_option( 'an_option' );
}
public function do_stuff() {
echo $tester;
}
}
$my_class = new MyClass();