<?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);
?>
- Output for 5.5.0 - 5.5.37, 5.6.0 - 5.6.23, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
- CurrentAccount Object
(
[account_number:Account:private] => 123456
[balance:Account:private] => 7896
[branch:Account:private] => Kochi
[account_owner:Account:private] => AccountHolder Object
(
[fullname:AccountHolder:private] => James
[age:AccountHolder:private] => 21
[mobile:AccountHolder:private] => 9495786
[account:AccountHolder:private] => CurrentAccount Object
*RECURSION*
)
[atm_issued:Account:private] =>
)
SavingsAccount Object
(
[account_number:Account:private] => 978563
[balance:Account:private] => 18765
[branch:Account:private] => Pala
[account_owner:Account:private] => AccountHolder Object
(
[fullname:AccountHolder:private] => John
[age:AccountHolder:private] => 29
[mobile:AccountHolder:private] => 974767345
[account:AccountHolder:private] => SavingsAccount Object
*RECURSION*
)
[atm_issued:Account:private] => 1
)
- Output for 8.3.5
- Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
CurrentAccount Object
(
[account_number:Account:private] => 123456
[balance:Account:private] => 7896
[branch:Account:private] => Kochi
[account_owner:Account:private] => AccountHolder Object
(
[fullname:AccountHolder:private] => James
[age:AccountHolder:private] => 21
[mobile:AccountHolder:private] => 9495786
[account:AccountHolder:private] => CurrentAccount Object
*RECURSION*
)
[atm_issued:Account:private] =>
)
SavingsAccount Object
(
[account_number:Account:private] => 978563
[balance:Account:private] => 18765
[branch:Account:private] => Pala
[account_owner:Account:private] => AccountHolder Object
(
[fullname:AccountHolder:private] => John
[age:AccountHolder:private] => 29
[mobile:AccountHolder:private] => 974767345
[account:AccountHolder:private] => SavingsAccount Object
*RECURSION*
)
[atm_issued:Account:private] => 1
)
preferences:
204.57 ms | 404 KiB | 261 Q