SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 27 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

So, let our journey begin, Happy OOPing with PHP.
??? ??? ??? ??? ??? ??? ???
???
Kick-Starting OOP
In this chapter we will learn how to create objects, define their attributes (or
properties) and methods. Objects in PHP are always created using a "class" keyword.
In this chapter we will learn the details of classes, properties, and methods. We
will also learn the scope of methods and about modifiers and the benefits of using
interfaces This chapter will also introduce us to other basic OOP features in PHP. As
a whole, this chapter is one of the better resources for you to kick-start OOP in PHP.
Let's Bake Some Objects
As I said before, you can create an object in PHP using the class keyword. A class
consists of some properties and methods, either public or private. Let's take the
Emailer class that we have seen in our first chapter. We will discuss here what it
actually does:
//class.emailer.php
class Emailer
{
private $sender;
private $recipients;
private $subject;
private $body;
function __construct($sender)
{
$this->sender = $sender;
$this->recipients = array();
}
public function addRecipients($recipient)
{
Kick-Starting OOP
[ 20 ]
array_push($this->recipients, $recipient);
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function setBody($body)
{
$this->body = $body;
}
public function sendEmail()
{
foreach ($this->recipients as $recipient)
{
$result = mail($recipient, $this->subject, $this->body,
"From: {$this->sender}\r\n");
if ($result) echo "Mail successfully sent to {$recipient}
";
}
}
}
?>
In this code, we started with class Emailer, which means that the name of our class
is Emailer.


Pages:
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
hotel jelenia góra Russian bride Free English grammar and study guid powiekszenia wielkoformatowe counter strike 1.6