Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class BankAccount
- {
- private static $nextAccNumber = 1;
- private $number;
- private $balance;
- public function __construct()
- {
- $this->number = self::$nextAccNumber;
- $this->balance = 0;
- self::$nextAccNumber++;
- }
- function getNumber()
- {
- return $this->number;
- }
- function getBalance()
- {
- return $this->balance;
- }
- public function depositCash($amount)
- {
- if (!is_numeric($amount) || $amount <= 0) {
- return false;
- }
- $this->balance += $amount;
- }
- public function withdrawCash($amount)
- {
- if (!is_numeric($amount) || $amount < 0) {
- return false;
- }
- $rest = $this->balance - $amount;
- if ($rest < 0) {
- return $amount;
- }
- $this->balance = $rest;
- return $amount;
- }
- public function printInfo()
- {
- echo "ID konta: " . $this->number . ", saldo: " . $this->balance . "<br>";
- }
- }
- $user1 = new BankAccount();
- $user2 = new BankAccount();
- $user3 = new BankAccount();
- $user4 = new BankAccount();
- $user5 = new BankAccount();
- var_dump($user3);
- var_dump($user5);
- var_dump($user1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement