Object Orientation - Beggining

Well, as my ideas of doing something very easy using the Objects Orientation in php to people who are starting now didn't work when i used the sql, i've decided to create this new tutorial based in a friend's doubt.

The idea is to compare two variables A and B to see if they are equal or not :D

Let's go!

We're going to create a class that will have our methods.

File Letter.class.php - the name has to be with capital letter and the .class.php

<?
//create the class that has to be in capital letter 'cause it's the name of the class
Class Letter{
//stating the variables
public $a;
public $b;
    //creating the constructor method and starting the variables
    function __construct($a,$b){
        $this->a = $a;
        $this->b = $b;
        }
    //creating a function that will check the variables
    public function checking(){
        if ($this->a==$this->b){
            echo "A is equal B";
        }
        else {
            echo "A isn't equal B";   
        }
    }
}
?>

 

File checking.php - this file will inclue the class to create the object and the form.

<?php
/ / Including class Letter
include_once ("Letter.class.php");
/ / Getting the GET variable form
$action = $_GET['action'];
if ($action == 'check') (
    / / Getting values form
    $a = $_POST['A'];
    $b = $_POST['B'];
    / / Creating and instantiating the object and letter assigning values to this object
    $letter = new Letter ($a, $b);
    / / Calling function check
    $letter->check();
)
?>
<form name="checking" method="post" action="?action=check">
<p>
<label for="a"> A: </ label>
<input name="A" type="text" id="a" />
<label for="b"> B: </ label>
<input name="B" type="text" id="b" />
<input type="submit" name="submit" value="Submit">
</ Form>

Any doubts or suggestion will be welcome.

See ya!

0
Your rating: None

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.