10.02.2013 Views

PHP Programming Language - OpenLibra

PHP Programming Language - OpenLibra

PHP Programming Language - OpenLibra

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PHP</strong> 200<br />

Basic example of object-oriented programming as described above:<br />

Class Person<br />

{<br />

}<br />

public $first;<br />

public $last;<br />

public function __construct($f,$l)<br />

{<br />

}<br />

$this->first = $f;<br />

$this->last = $l;<br />

public function greeting()<br />

{<br />

}<br />

return "Hello, my name is {$this->first} {$this->last}.";<br />

public function staticGreeting($first, $last)<br />

{<br />

}<br />

return "Hello, my name is $first $last.";<br />

$him = new Person('John','Smith');<br />

$her = new Person('Sally','Davis');<br />

echo $him->greeting(); // prints "Hello, my name is John Smith."<br />

echo '';<br />

echo $her->greeting(); // prints "Hello, my name is Sally Davis."<br />

echo '';<br />

echo Person::staticGreeting('John','Smith'); // prints "Hello, my name<br />

is John Smith."

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!