Following Script illustrates simple Object Oriented Programming in PHP. Script contains one class named "HelloWorld". Class contains variable named "world" and method/function named "getHtml()" to return message "Hello, World!". To call "getHtml()" method first we have to create object (in our example $greetings) of HelloWorld class. And using that object we are calling getHtml() method ($greetings->getHtml()). 
Output:
Hello, World!
Source Code:
<?php
class HelloWorld 
{
    public $world = 'World';
    function getHtml() 
    {
     return "<html><body>"."Hello, ".$this->world."!"."</body></html>";
    }
}
$greetings = new HelloWorld;
echo $greetings->getHtml();
?> 
0 comments :
Post a Comment