fork download
  1. <?php
  2.  
  3. class nemyx {
  4. public static function __callStatic($name, $arguments) {
  5. if ($name === 'eval') {
  6. return array_reduce($arguments, function($carry, $item) {return $carry * $item;}, 1);
  7. } else {
  8. die("Метод $name не найден.");
  9. }
  10. }
  11.  
  12. private $data = array();
  13.  
  14. function __construct() {
  15. $this->data = func_get_args();
  16. }
  17.  
  18. public function __call($name, $arguments) {
  19. if ($name === 'eval') {
  20. if(count($arguments) > 0) {
  21. die("Аргументы не требуются.");
  22. }
  23. return array_reduce($this->data, function($carry, $item) {return $carry * $item;}, 1);
  24. } else {
  25. die("Метод $name не найден.");
  26. }
  27. }
  28.  
  29. }
  30.  
  31. echo nemyx::{'eval'}(1, 2, 3, 4, 5) . PHP_EOL; // если написать nemyx::eval, то будет синт. ошибка
  32.  
  33. $kokoko = new nemyx(1, 2, 3, 4, 5);
  34.  
  35. echo $kokoko->eval() . PHP_EOL;
  36.  
Success #stdin #stdout 0.02s 24304KB
stdin
Standard input is empty
stdout
120
120