Non ci siamo, posto l'ultimo test eseguito semi copleto e vediamo se si trova la soluzione, le classi:
Codice PHP:
class site {
protected $output;
protected static $db;
public function __construct($db) {
self::$db = $db;
}
protected static function __callDb() {
return self::$db;
}
public function __showSite() {
return $this->output;
}
}
class page extends site { ... }
class head extends page { ... }
class title extends head {
private $title;
public function __construct() {
$this->db = site::__callDb();
$this->title = $this->__selectQuery();
}
private function __selectQuery() {
$query = "SELECT titolo FROM sezioni WHERE nome = %s LIMIT 1";
$this->db->__query($query, $this->page); //line 109
if (!$result = $this->db->__risultato()) {
throw new Exception('La query di selezione ' . $query . ' non funziona correttamente!!');
}
return '<title>' . $result . '</title>';
}
public function __showTitle() {
return $this->title;
}
}
L'esecuzione:
Codice PHP:
try {
$datiAccessoDb = array('host'=>'',
'user'=>'',
'password'=>'',
'database'=>''
);
$db = new database($datiAccessoDb);
$page = new page($db);
$title = new title();
$htmlTitle = $title->__showTitle();
$page->__setHead($htmlTitle);
$page->__buildSite();
echo $page->__showSite();
}
catch(Exception $e) {
echo $e->getMessage();
exit();
}
L'errore che mi ritorna è: Fatal error: Call to a member function __query() on a non-object in /mounted-storage/home75b/sub005/site.php on line 109
Da qui intuisco che l'oggetto db non passa come ci si aspetta.. Ho provato sia con $this->db = self::__callDb(); che con $this->db = site::__callDb(); ma nessun risultato migliore..
idee..