Call to objective function in fminsearch missing varargin?

I have just started using Octave and I am stumbling on the following fminsearch optimization code:

fun = @(x,a)100*(x(2) - x(1)^2)^2 + (a-x(1))^2;
[x,fmin] = fminsearch(fun,[-1,1.9],optimset(),3)
error: 'a' undefined near line 1 column 38
error: called from
    @<anonymous> at line 1 column 35
    fminsearch at line 168 column 10

I think line https://hg.savannah.gnu.org/hgweb/octave/file/76ccc1446f22/scripts/optimization/fminsearch.m#l182 should read fval = feval (fun, x, varargin{:});.

Or am I using fminsearch in the wrong way?

The “feature” you address works for historical reasons in Matlab, but is undocumented as it is officially discouraged (see “Minimize with Extra Parameters” in the fminsearch Matlab documentation). Octave decided not to support it, as Matlab might silently remove this feature at any time.

The encouraged procedure is

fun = @(x,a)100*(x(2) - x(1)^2)^2 + (a-x(1))^2;
a = 3;
fun2 = @(x)fun(x,a);
[x,fmin] = fminsearch(fun2,[-1,1.9],optimset())

Indeed it is old MATLAB code that I was running.

Thank you for the reply and the link to the previous discussion.