I have a PHP class like so:
<?php
class MyClass {
public $my_variable = array();
public function func1() {
$var1 = $this->my_variable;
array_push($var1, 'var1');
return $this->my_variable;
}
public function func2() {
$var2 = $this->my_variable;
array_push($var2, 'var2');
return $this->my_variable;
}
}
$my_class = new MyClass;
print_r($my_class->func1());
print_r($my_class->func2());
?>
The two print_r
functions return an empty array, and there are no errors displayed.
How can I get the "var1" and "var2" strings added to the $my_variable
array? I'm not sure where I am going wrong here...!
Thanks.