I’m developing an codeigniter application and want to create a user object in my application just to use for testing.
The following code is ran in the backend controller and I’m not sure if this is how it should be done.
class Backend_Controller extends MY_Controller
{
public $current_user = new stdClass;
public $current_user->group = 'User Group';
public $current_user->name = 'Kevin Smith';
public function __construct()
{
parent::__construct();
}
}
$current_user->groupisn’t a variable declaration. You are just assigning to a property of an already declared variable.Also, you can’t make function calls in the class declaration like that, you can only set constants.
PHP Docs: http://www.php.net/manual/en/language.oop5.properties.php
You need to use the constructor to make the object.