Reputation: 11693
As this does not seam to work?
class Site {
private $PROPERTIES = array(
"NAME",'STACKOVERFLOW',
"URL",'http:/stackoverflow.com'
);
function __construct() {
$this->props = $PROPERTIES;
}
function dumpData() {
var_dump($this->props)
}
}
Upvotes: 1
Views: 57
Reputation: 20475
I think what you want it a associative array?
private $PROPERTIES = array(
"NAME" => 'STACKOVERFLOW',
"URL" => 'http:/stackoverflow.com'
);
At least that is how I understood it. Because that would work.
$this->PROPERTIES['NAME'];
** fixed, thanks guys :P Too early for me...
Upvotes: 1
Reputation: 10074
function __construct() {
$this->props = $this->PROPERTIES;
}
Upvotes: 0
Reputation: 6299
In classes, reference class-level variables from functions using $this
:
function __construct() {
$this->props = $this->PROPERTIES;
}
Upvotes: 0
Reputation: 17703
you can but you missed the way of referencing properties...
instead use:
$this->props = $this->PROPERTIES;
Upvotes: 3