I have this code here:
class Class_name extends CI_Controller {
function __construct()
{
parent::__construct();
$this->user = array("value"=>"test");
}
public function index() {
print_r($this>user);
}
}
The problem is $this->user returns as 1 instead of the actual array. I have tried other variable names with no luck.
What am I doing wrong?
Peter
You just have a little typo here:
print_r($this>user);
change it to:
print_r($this->user);
You've got a typo.
print_r($this>user);
should be:
print_r($this->user);
This works fine:
class foo {
function __construct()
{
$this->user = array("value"=>"test");
}
public function index() {
print_r($this->user);
}
}
$foo= new foo();
$foo->index();
# Results in:
# Array
# (
# [value] => test
# )
As an interesting aside, this is because in PHP, objects are 'greater' than strings:
var_dump(new stdClass > 'foo');
# bool(true)
You should use the ->
in the line print_r($this>user)
Here is the edited script:
class Class_name extends CI_Controller {
function __construct()
{
parent::__construct();
$this->user = array("value"=>"test");
}
public function index() {
print_r($this->user);
}
}
public function index() {
print_r($this->user);
}