I keep getting fatal errors for the following code. What should I do to get rid of this error? I am trying to make an MVC Framework based site, the problem is with my Models. every thing else works fine.
<?php
class Model {
private $db;
private $session;
public function __construct() {
$this->db = new Database_Model;
$this->session = new Session_Model;
}
}
/**
* Database Class
*/
class Database_Model extends Model {
public function getUserInfo() {
return array(
'Thomas', 'Jane'
);
}
}
/**
* Session Class
*/
class Session_Model extends Model {
public function getUserId() {
return $_SESSION['uid'];
}
}
$b = new Database_Model;
$b->getUserInfo();
?>
You have created an infinite recursion scenario. Look:
Database_ModelandSession_ModelextendModel.Database_Model, the constructor inherited fromModelwill instance two additional objects on the constructor,$this->dband$this->session.Model, so they will also instance their ownDatabase_ModelandSession_Model.