1

Is there a nicer way to write this (preferably without eval!)?

function something($value, $operator) {
  switch ($operator) {
    case '=':
      return $this->arg == $value;
    case '<':
      return $this->arg < $value;
    case '>':
      return $this->arg > $value;
// etc.
  }
}

It's basicaly $operator($this->arg, $value) except you can't do that in PHP.

4

1 回答 1

0

只是为了完整——不要留下一个未回答的问题:在 PHP 5.6 之前没有办法做到这一点。

于 2014-06-21T03:07:22.777 回答