__destruct
method will be executed at the end (before the script stops execution)
class Bill {
    public $dinner = 20;
    public $dessert = 5;
    public $drink = 3;
    
    public $bill = 0;
    public function __construct() {
        $this->bill = 10;
    }
    public function dinner($count) {
        $this->bill += $count * $this->dinner;
        return $this;
    }
    public function dessert($count) {
        $this->bill += $count * $this->dessert;
        return $this;
    }
    public function drink($count) {
        $this->bill += $count * $this->drink;
        return $this;
    }
    public function __destruct() {
        echo $this->bill;
    }
}

$bill = new Bill;

$bill->dinner(3)->dessert(2)->drink(1);
by Valeri Tandilashvili
4 years ago
PHP
OOP
OOP PHP
2
Pro tip: use ```triple backticks around text``` to write in code fences