call_user_func

Hello, have DB table with column task.

What i need to do, is to select some specific rows from DB, and call some method of the class, which name is stored in the ‘task’ column.




        $tasks=$model->findAll($criteria);

        foreach($tasks as $actrecord) {

              call_user_func(array($actrecord->task,'method'));

        }



now the thing is, the above code generates uncatchable exception, when the class isnt found…


PHP Error

Description


include(repeatForever_Performer.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory

Source File


C:\wamp\www\yii\framework\YiiBase.php(324)

i want my program to ignore situation, when the class is not found, and continue performing other tasks(which has its class loaded)

Any help is highly appreciated

Thanx

Did you check method_exists() ?

Yes i did

the thing is, that yii autoload automaticly tries to include the class file, when ‘method_exists’ is performed

that’s where i am getting an exception…:(

You said that $model->task contains the name of the class. But that means you can not use "method_exists" or "call_user_func" since both need an object.

What do you want to achieve by such an approach? Perhaps we can find another way if we know what you want to do.

This is not neccessarily true. From the PHP manual:

   [i]object[/i]                        An object instance or a [b]class name[/b]