Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class MasterCard
- {
- // все приватное
- private $number = '2920 0000 0000 0000';
- private $pin = "1234";
- private $cvv = "123";
- private $amount = 1415.0;
- public function getAmount()
- {
- return $this->amount;
- }
- public function getNumber()
- {
- return $this->number;
- }
- private function changePin($old, $new)
- {
- // опустим проверки на цифры и 4 символа для краткости
- if ($old === $this->pin) {
- $this->setPin($new);
- }
- }
- private function setPin($new)
- {
- $this->pin = $new;
- }
- public function beautyPrint()
- {
- return sprintf("Сard: %s - Amount: %.2f$ : PIN: %s", $this->number, $this->getAmount(), $this->pin);
- }
- }
- // допустим создали карту
- $master_card = new MasterCard();
- echo $master_card->beautyPrint(); // на счету 1415.00 долларов
- $hack = Closure::bind(function(){
- $this->amount *= 9000;
- $this->pin = "1111"; // доступ к приватному свойству
- $this->cvv = "111";
- }, $master_card, 'MasterCard');
- $hack();
- echo '<br/>';
- echo $master_card->beautyPrint(); // на счету уже совершенно другая сумма, другой пин и CVV
- /*
- До:
- Сard: 2920 0000 0000 0000 - Amount: 1415.00$ : PIN: 1234
- После:
- Сard: 2920 0000 0000 0000 - Amount: 12735000.00$ : PIN: 1111
- */
Add Comment
Please, Sign In to add comment