3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Account { private $account_number; private $balance; private $branch; private $account_owner; private $atm_issued; function __construct($account_number,$balance,$branch,$account_owner,$atm_issued) { if($account_owner instanceof AccountHolder) { $this->account_number = $account_number; $this->balance = $balance; $this->branch = $branch; $this->account_owner = $account_owner; $this->account_owner->setAccount($this); $this->atm_issued = $atm_issued; } else { echo "Not a valid accountholder"; die(); } } } class SavingsAccount extends Account { private static $type = "SavingsAccount"; public static function getTypeOfAccount() { return self::$type; } } class CurrentAccount extends Account { private static $type = "CurrentAccount"; public static function getTypeOfAccount() { return self::$type; } } class AccountHolder { private $fullname; private $age; private $mobile; private $account; function __construct($name,$age,$mobile) { $this->fullname = $name; $this->age = $age; $this->mobile = $mobile; } public function setAccount($account) { $this->account = $account; } } $person_1 = new AccountHolder("James",21,9495786); $account_1 = new CurrentAccount(123456,7896.00,"Kochi",$person_1,false); $person_2 = new AccountHolder("John",29,974767345); $account_2 = new SavingsAccount(978563,18765.00,"Pala",$person_2,true); print_r($account_1); print_r($account_2); ?>

preferences:
46.89 ms | 402 KiB | 5 Q