How to access variables from other methods inside the same class in PHP?
问题 I tried this but couldn't get it to work: class Profile extends CI_Controller { public function index() { $foo = 'bar'; } public function form_submit() { echo $this->index()->foo; } } I know I can make a variable accessible to all the methods in a class by declaring it outside all the methods at class level and declaring it as public. But here I need to declare the variable inside one of the methods. 回答1: If you are declaring it inside the method, you are out of luck unless you return the