Skip to content

Instantly share code, notes, and snippets.

@zavodnoyapl1992
Last active October 4, 2019 14:45
Show Gist options
  • Save zavodnoyapl1992/ed9a13d2c1439778edcdc050e4398c6a to your computer and use it in GitHub Desktop.
Save zavodnoyapl1992/ed9a13d2c1439778edcdc050e4398c6a to your computer and use it in GitHub Desktop.
<?php
class Trans {
private $word;
public function __construct(string $word) {
$this->word = $word;
}
public function __invoke(array $replaces) {
return str_replace(array_keys($replaces), array_values($replaces), $this->word);
}
public function __toString() {
return $this->word;
}
}
$a = new Trans('Hello World');
echo $a;
echo $a(['Hello' => 'Buy']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment