Suppose I have this code:
class UserController extends Controller
{
protected $test;
public function __construct()
{
$this->test = new Test();
}
// first call this func
public function add_name()
{
$this->test->add_name('name1')
return $this->test->get_name();
}
// then this one
public function show_name()
{
return $this->test->get_name();
}
}
class Test
{
protected $name;
public function get_name()
{
return $this->name;
}
public function add_name($name)
{
$this->name = $name;
}
}
So when I call show_name() function after add_name() in UserController
(first class), return nothing. What is my code problem?
(when calling add_name() function it work correctly)