3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Account { private $accNumber; private $bal; private $branch; private $accOwner; function __construct($accNumber,$bal,$branch,$accOwner) { $this->accNumber = $accNumber; $this->bal = $bal; $this->branch = $branch; $this->accOwner = $accOwner; $this->accOwner->setAccount($this); } } class SavingsAccount extends Account { private $type = "SavingsAccount"; public function getTypeOfAccount() { return $this->$type; } } class CurrentAccount extends Account { private $type = "CurrentAccount"; public function getTypeOfAccount() { return $this->$type; } } class AccountHolder { private $name; private $age; private $mob; private $account; function __construct($name,$age,$mob) { $this->full = $name; $this->age = $age; $this->mob = $mob; } public function setAccount($account) { $this->account = $account; } } $person_1 = new AccountHolder("Nevil",29,933338787); $account_1 = new CurrentAccount(111111,77896.00,"Kaloor",$person_1); $person_2 = new AccountHolder("Chitra",23,9878787345); $account_2 = new SavingsAccount(222222,18765.00,"Edapally",$person_2); print_r($account_1); print_r($account_2); ?>
based on 4jrYk
Output for 5.5.0 - 7.3.0rc4
CurrentAccount Object ( [type:CurrentAccount:private] => CurrentAccount [accNumber:Account:private] => 111111 [bal:Account:private] => 77896 [branch:Account:private] => Kaloor [accOwner:Account:private] => AccountHolder Object ( [name:AccountHolder:private] => [age:AccountHolder:private] => 29 [mob:AccountHolder:private] => 933338787 [account:AccountHolder:private] => CurrentAccount Object *RECURSION* [full] => Nevil ) ) SavingsAccount Object ( [type:SavingsAccount:private] => SavingsAccount [accNumber:Account:private] => 222222 [bal:Account:private] => 18765 [branch:Account:private] => Edapally [accOwner:Account:private] => AccountHolder Object ( [name:AccountHolder:private] => [age:AccountHolder:private] => 23 [mob:AccountHolder:private] => 9878787345 [account:AccountHolder:private] => SavingsAccount Object *RECURSION* [full] => Chitra ) )