Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. <?php
  2. class Trans {
  3. private $word;
  4.  
  5. public function __construct(string $word) {
  6. $this->word = $word;
  7. }
  8.  
  9. public function __invoke(array $replaces) {
  10. return str_replace(array_keys($replaces), array_values($replaces), $this->word);
  11. }
  12.  
  13. public function __toString() {
  14. return $this->word;
  15. }
  16. }
  17.  
  18.  
  19. $a = new Trans('Hello World');
  20.  
  21. echo $a;
  22.  
  23. echo $a(['Hello' => 'Buy']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement