Is it possible to pass a variable to an event in a plugin? I need to find out if any changes have been made to the entry on successful save.

Using events entries.onBeforeSaveEntry and entries.onSaveEntry seems to be a way to do it. Maybe.

Can I pass some entry variables as arguments to the function on event listener?

public function init()
{
    parent::init();

    $oldVar = "";

    //Event: onBeforeSaveEntry
    craft()-&gt;on('entries.beforeSaveEntry', function (Event $event)
    {
        $entryModel = $event-&gt;params['entry'];
        $oldVar     = $entryModel-&gt;fieldVar;
    });

    //Event: onSaveEntry
    craft()-&gt;on('entries.saveEntry', function (Event $event)
    {
        $entryModel = $event-&gt;params['entry'];
        $newVar     = $entryModel-&gt;fieldVar;

        if ( $oldVar !== $newVar ){
            // ...
        }
    });
}
This will not work as the field value will be the new value in both events. You'll need to get the old value from the entry that exists in Craft before saving the new entry, and then perform the comparison. 

If the value has changed then store the entry ID to process once the entry has successfully saved. 

Note that the $entryIdChanged variable in the anonymous event functions is not in the same as that in the init() method. You can resolve this as follows:


Bring the $entryIdChanged variable into the anonymous functions using the use operator.  
PHP will by default "pass by value", meaning that if the value of the variable within the function is changed, it does not get changed outside of the function. So you should pass the variable in "by reference", using an ampersand &amp; before the variable name, which will change it outside the function as well.


See the PHP guide on Passing by Reference.  

public function init()
{
    parent::init();

    $entryIdChanged = null;

    // Event: onBeforeSaveEntry
    craft()-&gt;on('entries.beforeSaveEntry', function (Event $event) use (&amp;$entryIdChanged)
    {
        $entryModel = $event-&gt;params['entry'];
        $newVar     = $entryModel-&gt;fieldVar;

        $oldEntry = craft()-&gt;entries-&gt;getEntryById($entryModel-&gt;id);
        $oldVar = $oldEntry !== null ? $oldEntry-&gt;fieldVar : '';

        if ($oldVar !== $newVar){
            $entryIdChanged = $entryModel-&gt;id;
        }
    });

    // Event: onSaveEntry
    craft()-&gt;on('entries.SaveEntry', function (Event $event) use ($entryIdChanged)
    {
        $entryModel = $event-&gt;params['entry'];

        if ($entryModel-&gt;id === $entryIdChanged){
            // ...
        }
    });
}