I created Date() class. But it is not giving the desired outputs.
My code
<?php
class Date{
public $day = 1;
public $month = "January";
public $year = 2013;
public function __construct($dy, $mon, $yar){
$this->day = $dy;
$this->month = $mon;
$this->year = $yar;
}
public function lessthan($dt){
if($year != $dt->year)
return $year - $dt->year;
if($month != $dt->month)
return $month - $dt->month;
return $day - $dt->day;
}
public function pr(){
echo $day;
echo "<br>";
echo $month;
return;
}
}
$a = new Date(1,"January",2002);
$b = new Date(1,"January",2002);
$a->pr();
$b->pr();
echo "Hello";
?>
It only outputs
[newline]
[newline]
Hello
I changed the __construct() to this
public function __construct($dy, $mon, $yar){
this->$day = $dy;
this->$month = $mon;
this->$year = $yar;
}
But the output is still same. What is the mistake ?
EDIT : sorry for my mistake . i typed this->$day instead of $this->day