PHP Syntax OOP Classes Components Methods Calling


- Info:

- Methods are invoked in almost exactly the same fashion as functions.


- Example:

- This example shows how to call Method.

- Creat PHP Console Application Test.php.




//USE CLASS.----------------------------------------------------------

$myObject = new MyClass(); //Create Object from Class.

$myObject->displayVar(); //Function call: Hello from object!

MyClass::displayString(); //Function call: Hello from class!

echo($myObject->var); //Variable call: Hello from object!

//DEFINE CLASS.-------------------------------------------------------

class MyClass {

public $var = "Hello from object!\n";

public function displayVar() {



public function displayString() {

echo("Hello from classs!\n");