In the following code, variables user and permissions are not declared at the beginning like $data, $module etc. And these $this->user and $this->permissions are used in the extended class of this class.
My question is can I use variables without declaring and using $this->myvar?
Thanks in advance.
class MY_Controller extends CI_Controller {
// Deprecated: No longer used globally
protected $data;
public $module;
public $controller;
public $method;
public function MY_Controller()
{
.......
$this->user = $this->ion_auth->get_user();
.........
// List available module permissions for this user
$this->permissions = $this->user ?
$this->permission_m->get_group($this->user->group_id) : array();
Yes you can.
PHP automatically creates public properties when initially set, eg
The only time this differs is if you have a magic
__set($name, $value)method which will catch an attempt to write to an undefined or non-visible (in the current scope) property.