H
H
Hazrat Hajikerimov2014-12-28 21:15:00
PHP
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?
Mistake:

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){
                    view::tpl('header-nav',array(
                        '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)
A
Arman, 2014-12-28
@hazratgs

<?php
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