My Profile Photo

Personal Webpage of David Duggins


Well, I was born on a normal day in July, 1981 and have been creating chaos ever since. Born in North Carolina, but raised in the aftermath of the Soviet Union, Kazakhstan, I have been messing around with computers nearly my entire life. I wrote my first program in assembly when I was 11. In my early teens I ran a BBS connected to Fidonet and started building a website for my band. In 1999 I was introduced to Linux, and it was love at first compile. I started my career in IT in the early 2000's doing IT for a Car Dealership in Charlotte NC. I wrote my first major web app in Cold Fusion (an ecom app) at that time. In 2006 I left Charlotte and moved down to Columbia where starting working as a developer, freelancer and consultant. Currently I am working as a freelance developer and DevOps consultant!!


A lesson in Object Oriented PHP

\n I’ve casually referenced oo php recently. So here I am going to give a more formal tutorial on object oriented php for anyone out there who is unaware of OO programming in general. If you are familiar with OO programming, you will understand everything immediately.

The first thing that we are going to create is a class. This class will allow us to make an object based on that class.

Think of a class as a cookie cutter. We make objects from this class. Each object should be the same as all the others, except for the data that we place into the object.

class Car
{  
   var $make;      
   var $model;
}

Here we have defined our class “Car” as well as two variables, “make” and “model.” Now we have to make some setter methods for our class

function add_make($name)
 {  
    $this->make = $name;
 }

function add_model($name) {

    $this->model = $name;
 }

These two functions set the variables for the make and model. The next functions are called getter methods, because they ‘get’ the data from the object.

function get_make()
{  
   return $this->make;
}

function get_model()
{ 
    return $this->model;
}

Next we will build a driver file to test out our class.

require_once('carClass.php');

$myCar = new Car;
$myCar->add_make("Ford");
$myCar->add_model("Explorer");


echo $myCar->get_make();
echo $myCar->get_model();

Basically, we first create a new object “Car” called myCar. Then we add a make and a model to the Car object. Finally, we echo off the variables to see what we have set them as.

Here is the complete class file for you to study. For homework, make a getter and setter method for color and then add it to the driver file.

carClass.php:

class Car
{ 

   var $make; 

   var $model;
   var $color;

 function add_make($name)
 {  
    $this->make = $name;
 }

 function add_model($name)
 {  
    $this->model = $name;
 }

 function get_make()
 {  
    return $this->make;
 }

 function get_model()
 {  
     return $this->model;
 }


}
© 2024 David Duggins. All rights reserved.