Functional Area : Function and Method

Functions can be declared, in the global context or class context. Functions in classes are commonly called methods. See Variables, Scope and Runtime Contexts for variable scopes.

Any function calls can take any number of parameters. In a function/method declaration, the named parameters can be used in the code as local variables. If not enough number of parameters are specified at the runtime, null is used for the missing values. If there are more than the declared parameters, those extra parameters (beyond the declared ones) are accessed via the built-in array $$args . A function declaration can explicitly declare that it takes variable number of parameters by .. ; it does not actually do anything.

For class methods, data members should be accessed with this . prefix, otherwise they may be confused with variables. For a name without this . , if a non-null variable value is found, that variable/value is used; otherwise, try to find a data member with that name.

A class method is overridden by a same-name method in a derived class. The code in the child class method can invoke the parent's same-name method with the prefix super . .

Related Functional Areas

Related Syntax