фатальная ошибка «Невозможно использовать объект типа Closure as array», как исправить эту проблему. код, который я использую, приведен ниже
function message_broker_example_message_broker_consumers($self_name) { $consumers = array(); // An example consumer implemented using a closure. $consumers['helloWorldToEveryone'] = array( 'queue' => 'helloWorldForAll', 'callback' => function($message, \Closure $ack) { $message = json_decode($message->body); if ($message->name == 'crash') { throw new InvalidMessageException('Invalid name detected!'); } if (function_exists('drush_print')) { drush_print('Hello world, ' . $message->name); } else { drupal_set_message(t('Hello world, @name.', array('@name' => $message->name))); } $ack(); }, 'invalidMessageHandler' => function($message) { if (function_exists('drush_print')) { drush_print('Invalid message handler was executed.'); } else { drupal_set_message(t('Invalid message handler was executed.'), 'warning'); } });
код является фрагментом из модуля drupal message_broker
Попробуйте использовать call_user_func_array
function message_broker_example_message_broker_consumers($self_name) { $consumers = array(); // An example consumer implemented using a closure. $consumers['helloWorldToEveryone'] = array( 'queue' => 'helloWorldForAll', 'callback' => call_user_func_array(function($message, \Closure $ack) { $message = json_decode($message->body); if ($message->name == 'crash') { throw new InvalidMessageException('Invalid name detected!'); } if (function_exists('drush_print')) { drush_print('Hello world, ' . $message->name); } else { drupal_set_message(t('Hello world, @name.', array('@name' => $message->name))); } $ack(); }, [$message, $ack]), 'invalidMessageHandler' => call_user_func_array(function($message) { if (function_exists('drush_print')) { drush_print('Invalid message handler was executed.'); } else { drupal_set_message(t('Invalid message handler was executed.'), 'warning'); } }, [$message]));