That is possible, and what you’re doing is the general idea. You need to be more specific as to how it seems to be ‘not working’ though. Any errors? Debug info?
I change the function to protected function addB($a, $attr), add it to controller and use it as $this->addB($a, $attr), it works,
but when I add it [public function addB($attr)] in class and invoke it as class function $a->addB($attr) in controller it seems doing nothing and not error or debug info in apache log or application log…