Hazrat Hajikerimov2014-12-28 21:15:00
Hazrat Hajikerimov, 2014-12-28 21:15:00

Anonymous function inside PHP array?

Below is the code where the nav() method returns the processed data.
The problem is with the anonymous function. It is necessary for me in this order that the script would work out and return the data, as in js. Where are the errors in the code or is it not possible?

Catchable fatal error: Object of class Closure could not be converted to string in

class header {

    public function nav (){

        return view::tpl('header', array (
            'navigation' => function (){

                $sql = sql::getInstance();

                // Получаем список модулей
                $sql->where('nav', 'head');
                $modules = $sql->get('modules', null, array('name', 'module', 'nav'));

                foreach ($modules as $module){
                        'name'    => $module['name'],
                        'link'    => $module['module'],
                        'class'   => router::$module === $module['module'] ? 'active' : ''


Answer the question

In order to leave comments, you need to log in

1 answer(s)
Arman, 2014-12-28

echo is_callable($navigation) ? call_user_func($navigation) : $navigation;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question