I have a class called Converter
class Converter {
public function convert($value, $from, $to){
$this->switchUnitCall($from)($value, $to);
}
private function switchUnitCall($from){
switch($from){
case 'm':
return $this->fromM; break;
case 'km':
return $this->fromKM; break;
}
}
private function fromM($value, $to){}
private function fromKM($value, $to){}
}
I want to return the private method called fromM or fromKM to its caller, so I can call the fromM with my another custom arguments inside the convert method.
When I run the code above, I got error Undefined property: Converter::$fromM
My question, is it possible to return a method in PHP? and how is it done? Thank you.
convertmethod rather than having to pass it around.