I have the following piece of code in a codeigniter module controller:
class MyClass extends MX_Controller{
public $description = "index";
public function index(){
global $description;
echo $description;
}
}
According to normal PHP rules and the PHP documentation, this should work. However, it doesn't.
If I leave out the global $description I get a notice about the variable being undefined, but with it in place it doesn't seem to return anything.
Why aren't global variables working in this case?
You should do it like this instead of using global. This will work as you are in the scope of class so you need
$this