Learning PHP Object Oriented Programming
Today I have learned about using Object Oriented Programming (or OOP) in PHP. It is very easy once you understand the structure of the OOP and have lots of practice on this technique. I learned this while I was looking over my Google Reader before my PHP class. I’m taking beginning PHP course this semester. This means that the OOP topic is not included in this course. You need to know basic PHP structures like functions and loops in order to understand OOP. Fortunately, I already self-learned PHP language during the end of year in 2009 through Lynda,com. So I tried to use OOP in the PHP script. At first. I think that I will practice more of this technique because this is new to me. I followed the simple tutorial on this website. After finishing the tutorial, I went to attend the PHP class. To me surprise, it had a test today. I happened to need more practice over the OOP. I took the second part of the test which was the hands-on test entirely using OOP. Here is the Object-oriented based test page. The following is one of the classes I created:
class todayDate {
public $month;
public $mesg;
public function __construct($tdMon) {
date_default_timezone_set(“America/New_York”);
$tdDate = date($tdMon);
$this->month=$tdDate;
switch ($tdDate) {
case “June”:
case “July”:
case “August”:
$this->mesg=”Drive safely: school is in session”;
break;
default: $this->mesg=”Enjoy your vacation: Drive safely”;
}
}
public function getMonth() {
return $this->month;
}
public function displayMsg() {
return $this->mesg;
}
}
I just learned the basics of Object Oriented Programming so I can only write these basic classes. As I learn more about OOP, I will improve my code for better readability and performance.
For more information and to learn more about Object Oriented Programming in PHP, visit this article on devarticles.com.
There are no posts related to Learning PHP Object Oriented Programming.