I have added closure inside the constructor and unsure of its performance as well as best practice. What is the best way to do that if it is not the right way to do it?
<?php
class Foo
{
private $operation;
public function __construct(){
$this->operation = [
"==" => function($a,$b) {return $a == $b;}
];
}
public function processComparision($operand1,$operator,$operand2){
if($operator == "=="){
$func = $this->operation[$operator];
return $func($operand1,$operand2);
}
}
}
?>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…