MATLAB: Do I receive a “Maximum recursion limit of 500 reached” error when I try to SET or GET a dynamic property using an anonymous function in MATLAB 7.6 (R2008a)

classclassesMATLABmcosoop

I have a class defined as follows:
classdef testClassDynProps<dynamicprops
methods
function obj=testClassDynProps
metaProp = obj.addprop('testProp');
metaProp.SetMethod = @(obj,val) (testClassDynPropsSetMet(obj,val));
metaProp.GetMethod = @(obj) (testClassDynPropsGetMet(obj));
end % constructor
end
end
I invoke this as follows:
t=testClassDynProps;
t.testProp = 3; % this will result in infinite recursion

a = t.testProp; % this will result in infinite recursion
I receive the following error message:
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in ==> testClassDynProps>@(obj,val)(testClassDynPropsSetMet(obj,val))
The Set and Get methods of a dynamic property created with addprops in a subclass of dynamicprops create infinite recursions, because the Get/Set functions call themselves.

Best Answer

This change has been incorporated into the documentation in MATLAB 7.8 (R2009a).
For previous releases, read below for any additional information:
This is expected behavior based on how SET/GET functions and anonymous functions work. Only the SET/GET functions can SET/GET the actual property values. An anonymous function that calls another function to do the actual work cannot SET/GET the actual property value just as an ordinary SET/GET function cannot call another function to SET/GET the actual property.
To work around this issue, invoke the function as follows:
metaProp.SetMethod = @testClassDynPropsSetMet;
metaProp.GetMethod = @testClassDynPropsGetMet;