Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arguments to be passed as references #86

Closed
wants to merge 1 commit into from

Conversation

raffis
Copy link
Contributor

@raffis raffis commented Dec 5, 2019

Currently it is possible to attach arguments to the emitter which will get passed to listeners.
Those arguments get passed by value since internally func_get_args() gets used.

It would be very useful to pass arguments by reference to allow listeners to inject stuff into the emitting context.

This pr makes this possible while still be fully compatible.
A listener may now request an argument as reference:

$emitter->addListener('foo', $value, &$anothervalue) {
   $value = 'bar';
   $anothervalue = 'bar';
});

$value="foo";
$anothervalue="foo"
$emitter->emit('foo', $value, $anothervalue);
var_dump($value); //prints string(3) "foo"
var_dump($anothervalue); //prints string(3) "bar"

@raffis
Copy link
Contributor Author

raffis commented Dec 7, 2019

Note build fails because of eol php versions on travis, fixed by #87

@frankdejonge
Copy link
Member

The next version will not support arbitrary argument passing, instead, it's advised to use event objects with properties on the event classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants