You know that in object-oriented programming, we write all our code statements in a class. So here, you will know that if a class has a function in it then how to call it.
- The first step is to create an object by class name. And make sure you added a 'new' keyword before. Store this object in a variable like that:-
$result = new test();
- Now, $result is an object, So to call function access it from $result object as a method like this : -
$result->first();
See the example below.
<?php
class test{
function first()
{
echo "Function is called.";
}
}
$result = new test();
$result->first();
?>
Note *** In object-oriented programming, variables inside a class called as property and functions are known as methods.
Also, read these articles
Publish A Comment