How to access a variable from different functions of the same class?
You can't.
In order to get to that variable, you'd need to put it outside of the function itself.
class MyController extends CI_Controller{ private $variable; private function act() { $input = (response from client) return $input } private function a() { $this->variable = $this->act(); }}
Doing that will make you able to access the variable from everywhere within the class.
Hope this helps.
Its simple in your class
define a variable like
in controller class below function is written. Class myclass {public $_customvariable;function act(){ //some code for connection $this->_customvariable= $input = (response from client); return $input;}function a() {$a = $this->act(); }function b(){ echo $this->_customvariable;//contains the $input value } }
class fooBar { private $connection; public function __construct() { $this->act(); } public function act(){ //some code for connection $this->connection = (response from client); } public function a() { doSomething($this->connection); } public function b() { doSomething($this->connection); }}