Yes it is possible. Starting in PHP 5.4, you can call object methods through the [$this, 'methodName'] construct
[$this, 'indexAction'](5);
You can use this construction, for example,
<?php class MyClass { public function indexAction($id) { echo "MyClass::indexAction($id)<br />"; } public function aboutAction($id) { echo "MyClass::aboutAction($id)<br />"; } public function call($name, $id = 0){ $actions = [ 'index' => [$this, 'indexAction'], 'about' => [$this, 'aboutAction'] ]; $actions[$name]($id); } } $obj = new MyClass(); $obj->call('about', 5); // MyClass::aboutAction(5)
call_user_functo run, then['index' => [$this, 'indexAction']]andcall_user_func($action['index']). did not try. - Deadooshkaclass my { public function a() { echo "a". "\n"; } public function b() { echo "b". "\n"; } } $arr = array('a', 'b'); $i = new my(); $i->{$arr[1]}();class my { public function a() { echo "a". "\n"; } public function b() { echo "b". "\n"; } } $arr = array('a', 'b'); $i = new my(); $i->{$arr[1]}();- splash58static $names = array('a', 'b');and$i->{my::$names[1]}();- splash58$i->{$arr[1]}()- Sergiy$arr[0] = 'indexAction', then$i->{$arr[0]}()equivalent to$i->indexAction()- Aleks G