A Class With A Method

 

PHP is an Object Oriented Programming language. So, everything must defined in objects. This example will guide you to create class object.

<html>
<head>
<title>A Class with a Method</title>
<body>
<?php

// written by frozenade

class first_class{
var $me;
var $you;

function sayHello(){
print “hello <br />”;
$this->me = “this is me <br />”;
}
function sayHelloToo(){
print “<br />hello too <br />”;
print “you said: ” . $this->me;
$this->you = “and i see you”;
}
}

$obj = new first_class();

$obj->sayHello();
print $obj->me;

$obj->sayHelloToo();
print $obj->you;

?>
</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: