Reputation: 31
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();
?>
Upvotes: 1
Views: 8875
Reputation: 71908
You have created an infinite recursion scenario. Look:
Database_Model
and Session_Model
extend Model
.Database_Model
, the constructor inherited from Model
will instance two additional objects on the constructor, $this->db
and $this->session
.Model
, so they will also instance their own Database_Model
and Session_Model
.Upvotes: 11