- time: documentation ( source)
- date: documentation ( source)
<?php
class Animal {
protected $what = "nothing";
protected $born;
public function __construct() {
$this->born = time();
}
function sound() {
echo get_class($this)." says {$this->what}";
}
function getBorn() {
return $this->born;
}
}
class Cow extends Animal {
protected $what = "moo";
protected $owner;
public function __construct($owner) {
$this->owner = $owner;
//must explicitly call parent::__construct to avoid wrong result;
}
}
$a = new Cow("Old McDonald");
$a->sound();
echo "Cow was born on ",date("M j, Y",$a->getBorn());