Definitely agree with everyone else. You should read up on the 550 million online PHP manuals including the links provided in other answers. In the meantime, you get this:
class one {
private $name;
const ONE = 'ONE';
// php magic function. allocate memory for object upon instantiation
// called with new
public function __construct($name = null) {
$this->init($name);
}
protected function name() {
return $this->name;
}
// php magic function called when object variable is accessed in a string context
public function __toString() {
return __CLASS__ . ': ' . $this->name;
}
// static functions can be called without instantiation
public static function con() {
echo self::ONE;
}
private function init($name) {
$this->name = $name;
}
}
// two cannot overwrite method init() -- it is private.
// two has no access to $name. It is private in one and not visible to two
class two extends one {
// protected methods can be overwritten
protected function name() {
return parent::name();
}
// so can public methods
public function __toString() {
return __CLASS__ . ': ' . $this->name();
}
}
// static method call; no instantiation needed
echo one::con() . "\n"; // ONE
// public methods can be called by child class
echo two::con() . "\n"; // ONE
$one = new one('uno');
echo "$one\n"; // one: uno
$two = new two('dos');
echo "$two\n"; // two: dos
$one->name(); // bork! No public access to this method