Guest User

Untitled

a guest
Mar 21st, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2.  
  3. class MasterCard
  4. {
  5.     // все приватное
  6.     private $number = '2920 0000 0000 0000';
  7.     private $pin = "1234";
  8.     private $cvv = "123";
  9.  
  10.     private $amount = 1415.0;
  11.  
  12.     public function getAmount()
  13.     {
  14.         return $this->amount;
  15.     }
  16.  
  17.     public function getNumber()
  18.     {
  19.         return $this->number;
  20.     }
  21.  
  22.     private function changePin($old, $new)
  23.     {
  24.         // опустим проверки на цифры и 4 символа для краткости
  25.         if ($old === $this->pin) {
  26.             $this->setPin($new);
  27.         }
  28.     }
  29.  
  30.     private function setPin($new)
  31.     {
  32.         $this->pin = $new;
  33.     }
  34.  
  35.     public function beautyPrint()
  36.     {
  37.         return sprintf("Сard: %s - Amount: %.2f$ : PIN: %s", $this->number, $this->getAmount(), $this->pin);
  38.     }
  39. }
  40.  
  41. // допустим создали карту
  42. $master_card = new MasterCard();
  43.  
  44. echo $master_card->beautyPrint(); // на счету 1415.00 долларов
  45.  
  46. $hack = Closure::bind(function(){
  47.     $this->amount *= 9000;
  48.     $this->pin = "1111"; // доступ к приватному свойству
  49.     $this->cvv = "111";
  50. }, $master_card, 'MasterCard');
  51.  
  52. $hack();
  53.  
  54. echo '<br/>';
  55.  
  56. echo $master_card->beautyPrint(); // на счету уже совершенно другая сумма, другой пин и CVV
  57.  
  58. /*
  59. До:
  60. Сard: 2920 0000 0000 0000 - Amount: 1415.00$ : PIN: 1234
  61.  
  62. После:
  63. Сard: 2920 0000 0000 0000 - Amount: 12735000.00$ : PIN: 1111
  64. */
Add Comment
Please, Sign In to add comment