Archive

Archive for November, 2008

PHP Programmer Tutorial for Building an OOP Class.

November 13th, 2008

A class is a representation of an abstract data type. What this means to the PHP Programmer is that a class is a schematic for building or constructing our box. It consists of variables and functions that allow that fictional click. With this schematic, we can construct our box exactly how we want.

class Box
{
var $stuff;

function Box($stuff) {
$this->contents = $stuff;
}

function click_box() {
return $this->contents;
}
}

$aBox = new Box(”Alex”);
echo $aBox->click_box();

If we look at our schematic, it has a variable $stuff which is used to remember what is in the box. It also has two functions: Box and click_box.

When we “click” the box, PHP will look for and execute the function with the same name as the class. This is all that the function does, initialize the content of the box when clicked.

The variable $this is used for telling the Box that contents is a variable that belongs to the whole class and not the function. The $stuff variable will only exist inside the scope of the function Box. $this->contents is a variable that was defined to be part of the entire class.

The function click_box will return the value stored within the class’ contents variable, $this->contents.

When the PHP Programmer executes the entire script, the class Box is defined, new constructs or builds the box and passes Alex to its function. This function, which has the same name as the class, will accept the value passed to it and it will also store it within the class variable. This way it will be accessible to all of the functions throughout the class.

OOP

PHP Programmer Introduction to OOP Programming & Creating an Object.

November 13th, 2008

In this tutorial I will explain how to start OOP properly and how to polish your skills as a PHP Programmer.

Object-Oriented Programming (OOP) tutorials can be filled with programming theory and big words such as inheritance, encapsulation and abstraction. You will see that many will explain code by comparing their samples to toasters and car radios, which should help confuse the reader some.

Once you take away all the big words and chest bumping that comes with OOP, you will find it interesting and very helpful. As the years move along you will understand why…

I don’t want this to be another cookie-cutter tutorial that only serves to confuse you.
It is this PHP Programmer’s intention to explore OOP with you in a way that will help you sharpen your skills as a PHP Developer. As I mentioned, over the years you will build a foundation that is strong and helpful to yourself and others.

I want you to imagine a box. This box can be any type of box: Cardboard, Wood, Plastic,Rubber, Small, Large…

Next, imagine that you placed something inside this box: a pebble, a book, a box of matches…

Wouldn’t it be neat to touch the box and then it tells us what is inside of it? Actually, with OOP it is possible!!

$aBox = new Box(”Alex”);
echo $aBox->click_box();

The variable $aBox is equal to our new magical Box(). What is known to PHP Programmer’s in OOP as an object.

Now that we have an active variable($aBox) representing the Box(), we want to put Alex in the box. When we want to “click” the button to tell us whats inside of this box, we will ask using a get_whats_inside function to $abox.

As you figured, we cannot run this code yet. We havent given any directions as to what the click button is supposed to do. You will find this in our next section on classes.

Next Section - Classes

OOP

How To Create A Simple Hello World Script

November 10th, 2008

This is a simple tutorial on how to create a simple PHP Hello World script. This basic knowledge will get the novice PHP Programmer get started with building their first PHP script. First off we will need to create the delimiters for PHP as follows:

<?php

……

?>

This will allow you to paste the code so that the server can begin translating what is between the PHP delimiter tags. Every PHP programmer is very familiar with these delimiters and uses them in most or all of their PHP development.

Our next step will show you how to “Print” or echo the PHP Hello World Text to the browser page.

<?

echo “Hello, World!”;

?>

This is what your output will look like:

Hello, World!

That is it! Our PHP Programmer has shown you how to create a simple Hello World PHP script. Now go try it out on your server and come back and leave a comment as to how it went or other suggestions that you may have.

Basics

Welcome to my new PHP development site for PHP Programming.

November 9th, 2008

I would like to be the first to welcome you to my new site for PHP Programmers. My intent is to help noobies to develop their new skills here on CT Coder. I will be creating posts regarding PHP programming, MYSQL Administration, And how to easily and effectively sell your freelance services.

Announcements