php - How to call a function from an array, which is in a class -


my problem this, have function stored in array part of class. want call function array using call_user_func() can't seem figure out how write this.

calling function array not in class can done such.

 $thearray = array( 0 => 'funcone', 1 => 'functwo');  call_user_func($thearray[0]); 

however when try array in class, sent work, imagine because need reference class somehow. know can call function class this:

 call_user_func(array($myclass, 'funcone')); 

but question how call function array, within class, using call_user_func(); hope can me this, have feeling matter of how written.

assuming array within class public, can do:

call_user_func(array($myclass, $myclass->thearray[0])); 

did answer question?

update:

i tried following , worked:

<?php class foo {     public function bar() {         echo "quux\n";     }      public $baz = array('bar'); }  $foo = new foo(); call_user_func(array($foo, $foo->baz[0]));  shell$ php userfunc.php  quux 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -