Studiati questo codice:
P.S. Non utilizzare delle parole riservate (es. parent) per i nomi delle classi.Codice PHP:
<?php
class root {
protected static $db;
public function __construct($db) {
self::$db = $db;
}
protected static function __callDb() {
return self::$db;
}
}
class child extends root {}
class nephew extends child {
function print_db() {
echo(self::__callDb());
}
}
$nephew = new nephew('test');
$nephew->print_db();
?>