Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How Can I replace Closures with zephir

PHP Code:

     $eventsManager->attach('db', function ($event, $db) use ($log) {

                if ($event->getType() == 'beforeQuery') {

                    $log->info($db->getRealSQLStatement().json_encode($db->getSqlVariables()));

                }

                if ($event->getType() == 'beforeSave') {

                    $log->info($db->getRealSQLStatement());

                }

            });

zephir Code:

     eventsManager->attach("db", call_user_func_array(function (event, db,log){

            if (event->getType() == "beforeQuery") {

                log->info(db->getRealSQLStatement().json_encode(db->getSqlVariables()));

            }

            if (event->getType() == "beforeSave") {

                log->info(db->getRealSQLStatement());

            }

        },[[event,db,log]]));

ERROR:

Cannot read variable 'event' because it wasn't declared

},[[event,db,log]]));

Could you please provide full method?



4.5k
edited Jun '16

no method.

this is the php code.

    $eventsManager->attach('db', function ($event, $db) use ($log) {

                if ($event->getType() == 'beforeQuery') {

                    $log->info($db->getRealSQLStatement().json_encode($db->getSqlVariables()));

                }

                if ($event->getType() == 'beforeSave') {

                    $log->info($db->getRealSQLStatement());

                }

            });

it is a Closures. I want to use PHP's call_user_func_array in zephir to realize the Closures functions.

zephir Code:

I mean this



5.9k
Accepted
answer
edited Jun '16

See here https://github.com/phalcon/cphalcon/search?utf8=✓&q=call_user_func_array&type=Code



4.5k

Yes.

Thank You.