Basic OOP ...
Posted: Thu May 07, 2009 4:02 pm
Hi, I'm pretty new to OOP in PHP. However, I'm not sure why the below code don't work. Please give kind advise!
***** Please add
above prints "--"
Please help~~~
***** Please add
Code: Select all
tag when posting source *****[/color]Code: Select all
class Dateinfo {
public $year, $month, $day;
function __construct($p_year, $p_month, $p_day){
$this->$year = $p_year;
$this->$month = $p_month;
$this->$day = $p_day;
}
function __get($name){
return $this->$name;
}
function __set($name, $value){
$this->$name = $value;
}
function getToday(){
$today = $this->$year."-".$this->$month."-".$this->$day;
return $today;
}
}
$dateinfo = new Dateinfo(date('Y'), date('m'), date('d'));
print_r($dateinfo->getToday());
Please help~~~