Reputation: 1661
When I run this code, I get only "in constructor" being printed out.
Why am I not seeing the array being printed out?
Apache log shows no errors. PHP syntax checkers show no errors.
<?php
//---- User Class ----
class User {
private $list;
function __construct() {
echo "in constructor";
$this->$list = array(1, 2, 5);
}
function printAll() {
print_r($this->$list);
}
} // end Class
$foo = new User();
$foo->printAll();
?>
Upvotes: 0
Views: 10170
Reputation: 7887
a $ to much, try this
When I run this code, I get only "in constructor" being printed out.
Why am I not seeing the array being printed out?
Apache log shows no errors. PHP syntax checkers show no errors.
class User {
private $list;
function __construct() {
echo "in constructor";
$this->list = array(1, 2, 5);
}
function printAll() {
print_r($this->list);
}
}
Upvotes: 5
Reputation: 1
Yes $this->varname is the proper syntax which we mix up some times.
class Cname {
var $name;
function setName($nam)
{
$this -> name = $nam;
}
}
Upvotes: 0