So I have notice during a print_r statement this creates a circular reference.
Should I avoid having both classes having each other as a parameter?
Aside from the print_r statement (which php seems to recognize as circular and not continue to print_r forever) is there other reasons I should not do this?
Class Account
{
private $id;
private $name;
private $User; /** User object **/
function __construct($User, $name){
$this->User = $User;
$this->name = $name;
}
}
Class User
{
private $id;
private $name;
private $accounts = array(); /** An array of Account Objects **/
function __construct($name){
$this->name = $name;
}
function addAccount($Account){
array_push($this->accounts, $Account);
}
}
$User = new User("Joe");
$Account = new Account($User,"accountname");
$User->addAccount($Account);