How to send $data by reference

Hello,

I've custom event:

$eventsManager->fire('user/authorize:beforeLogin', null, $properties);

where's $properties is an array.

event handler:

$eventsManager->attach('user/authorize:beforeLogin', function(\Phalcon\Events\Event $event){

$data = $event->getData();

$data->field = 'my new data';

$event->setData($data);

}, 100);

How can i send $properties as a reference and below in code,and use updated $properties?

I know following way, but it looks ugly and unpractical for me

$properties = (object)$properties;

$eventsManager->fire('user/authorize:beforeLogin', null, $properties);

Any suggestions?



2.9k
edited Aug '16

& ?

nope, it doesn't work, i've tried

$eventsManager->attach('user/authorize:beforeLogin', function(\Phalcon\Events\Event $event, $component, &$data){
    $data['test'] = 'woop!';
}, 100);

Warning: Parameter 3 to {closure}() expected to be a reference, value given in

Then im guessing no other way, you need to use object.



2.9k

Then im guessing no other way, you need to use object.

Exists 1 more way, bit I dislike it too

$eventsManager->fire('user/authorize:beforeLogin', null, [&$options]);

and

$eventsManager->attach('user/authorize:beforeLogin', function(\Phalcon\Events\Event $event, $component, $data){

$data[0]['test'] = 'woop!';

}, 100);