Calling Class Operations

chinmay.sahoo

New member
You can call class operations in much the same way that you call class attributes. Say you have the class

Code:
class classname
{
function operation1()
{
}
function operation2($param1, $param2)
{
}
}
and create an object of type classname called $a as follows:

Code:
$a = new classname();

You then call operations the same way that you call other functions: by using their name and placing any parameters that they need in brackets. Because these operations belong to an object rather than normal functions, you need to specify to which object they belong.The object name is used in the same way as an object’s attributes, as follows:

Code:
$a->operation1();
$a->operation2(12, ‘test’);

If the operations return something, you can capture that return data as follows:

Code:
$x = $a->operation1();
$y = $a->operation2(12, ‘test’);
 
Back
Top