PHP Syntax OOP Objects

 

- Info:

- Object is instantiation of a Class.

 

- Example:

- This example shows how to create an Object from Class

- Creat PHP Console Application Test.php.

 

Test.php

<?php

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

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

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

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

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

class MyClass {

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

public function displayString() {

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

}

}

?>