| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
Syntax Warnings and Property Names |
The MATLAB M-Lint code analyzer helps you optimize your code and avoid syntax errors while you write code. It is useful to understand some of the rules that M-Lint applies in its analysis of class definition code. This understanding helps you avoid situations in which MATLAB allows that is undesirable.
M-Lint warns about the use of variable names in methods that match the names of properties. For example, suppose a class defines a property called EmployeeName and in this class, there is a method that uses EmployeeName as a variable:
properties EmployeeName end methods function someMethod(obj,n) EmployeeName = n; end end
While the previous function is legal MATLAB code, it results in M-Lint warnings for two reasons:
The value of EmployeeName is never used
EmployeeName is the name of a property that is used as a variable
If the function someMethod contained the following statement instead:
obj.EmployeeName = n;
M-Lint generates no warnings.
If you change someMethod to:
function EN = someMethod(obj) EN = EmployeeName; end
M-Lint returns only one warning, suggesting that you might actually want to refer to the EmployeeName property.
While this version of someMethod is legal MATLAB code, it is confusing to give a property the same name as a function. Therefore, M-Lint provides a warning suggesting that you might have intended the statement to be:
EN = obj.EmployeeName;
Suppose you define a method that returns a value of a property and uses the name of the property for the output variable name. For example:
function EmployeeName = someMethod(obj) EmployeeName = obj.EmployeeName; end
M-Lint does not warn when a variable name is the same as a property name when the variable is:
An input or output variable
A global or persistent variable
In these particular cases, M-Lint does not warn you that you are using a variable name that is also a property name. Therefore, a coding error like the following:
function EmployeeName = someMethod(obj) EmployeeName = EmployeeName; % Forgot to include obj. end
does not trigger a warning from M-Lint.
![]() | A Class Code Listing | Functions Used with Objects | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |