PHP Trait

<?php 




class BankAccount{
    public $accountNumber;
    public $accountBalance;

    public function setAccountNumber($account_no){
        $this->accountNumber = $account_no;
    }

    public function getAccountNumber(){
        echo "Account No: $this->accountNumber  <br>";
    }

    public function initiateAccountBalance($account_balance){
        $this->accountBalance = $account_balance;
    }

    public function getAccountBalance(){
        echo "Account Balance: $this->accountBalance  <br>";
    }
}


trait Bkash{
    public $bkashAccountNo;
    public $bkashBalance;

    public function setBkashAccountNo($bkash_no){
        $this->bkashAccountNo = $bkash_no;
    }

    public function getBkashAccountNo(){
        echo "Bkash Account No: $this->bkashAccountNo  <br>";
    }

    public function setbkashBalance($bkash_bal){
        $this->bkashBalance = $bkash_bal;
    }

    public function getbkashBalance(){
        echo "Bkash Account Balance: $this->bkashBalance  <br>";
    }
}

class Customer extends BankAccount{
    use Bkash;
    public $name;
    public function setName($name){
        $this->name = $name;
    }
    public function getName(){
        echo "Account Name: $this->name  <br>";
    }
}


$sujon = new Customer();

$sujon->setAccountNumber('1');
$sujon->initiateAccountBalance('100');
$sujon->setName('Sujon Kumar Dey');
$sujon->getName();
$sujon->getAccountNumber();
$sujon->getAccountBalance();
$sujon->setBkashAccountNo('01768203686');
$sujon->getBkashAccountNo('01768203686');
$sujon->setbkashBalance('500');
$sujon->getbkashBalance('500');




?>

Leave a Comment