How to pass parameters by reference to a batch? I need to process a parameter in a batch function where the result will be kept after the function ends and it should be then passed in the finished function of the same batch.
Is there a way to pass the parameters by a reference, so that any changes to that parameter are saved?

Example:

$params = [$a, $b];
$finishedParams = [$a, $b];
$batch = ['title' =&gt; 'Sample processing batch',
          'operations' =&gt; ['someFunction', $params],
          'finished' =&gt; ['finishedFunction', $finishedParams]
         ];
...
public static function someFunction(&amp;$a, $b){
    $a = 'somethingChanged';
}
public static function finishedFunction($success, $results, $operations){
   // Use $a variable when somethingChanged after the batch process.
}
Alfred is right. You can achieve that by using the $context parameter.

public static function someFunction($a, $b, &amp;$context) {
  // Store data in $context['results'] entry.
  // my_var will keep that value.
  $context['results']['my_var'] = 20;
}