Create Class and Function in PHP

To create a professional-look programming, we need to create object source implemented in class and function.

This is a good tutorial to start learning about class and function environment in PHP.

Create an index file, name it main.php
Insert these into body section.

<form action=”<?php print(basename(__FILE__)); ?>?act=doit” method=”post”>
Name : <input type=”text” name=”name” />
Age : <input type=”text” name=”age” />
<input type=”submit” value=”Process” />
<input type=”reset” value=”Reset” />

if ($_GET[‘act’] == “doit”) {

if ($_POST[‘age’] < 20) {
else {



Then create a file, name it class.php

// written by frozenade

class operation {

function one() {
$var1 = $_POST[‘name’];
$var2 = “You are a teenager!”;
echo “Hello, $var1! $var2”;

function two() {
$var1 = $_POST[‘name’];
$var2 = “You are an adult!”;
echo “Hello, $var1! $var2”;


$op = new operation();

class selection {

function age1() {
global $op;

function age2() {
global $op;


$select = new selection();

File class.php is an object file within class and function to be used in form processing.

4 Responses to Create Class and Function in PHP

  1. Idetrorce says:

    very interesting, but I don’t agree with you

  2. frozenade says:

    oh, which part does it?
    plase tell me.

  3. wina says:

    Salam kenal,

    aku mo tanya yang di buat diatas itu PHP untuk RSS ya,
    kalo aku ingin mmbuat PHP mnj .RDF,

    file nya udah berhasil dibuat, cuma code/sintax yang diperlukan untuk mendapatkan variable di PHPnya msh ngawang (alias bingung)…
    ada tutorialnya gak? PHP to RDF

    makasih atas balasannya..

Leave a Reply

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

You are commenting using your 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: