Dentafrice,
26-10-2007, 11:38 PM
Well this is a tutorial on the introduction to PHP classes.
Required knowledge:
Basic knowledge of PHP.
Functions.
Lets begin, you know to tell apache to enter PHP mode we need to enter the PHP syntax:
<?php
?>
Lets start to build our class, we are going to make a "check username" class.
First we need to declare that this is going to be a class:
<?php
class check_username
{
}
?>
class - tells PHP this is a class
check_username is the name of the class used later in this tutorial.
Lets begin with a VAR. It is a variable, just like $bob is a variable.
<?php
class check_username
{
var $username;
}
?>
Now, lets begin our "check username" function:
<?php
class check_username
{
var $username;
function check()
{
}
}
?>
That declares that we are ready for a function. Lets add a little to the function to check the username. We need a username to check against so lets add another variable.
<?php
class check_username
{
var $username;
var $c_username;
function check()
{
}
}
?>
Now lets make it check the username:
<?php
class check_username
{
var $username;
var $c_username;
function check()
{
if ($this->username != $this->c_username)
{
echo "That username is not correct!";
}
else
{
echo "That is a correct username!";
}
}
}
?>
if($this->username != $this->c_username)
if the variable $username does not equal the variable $c_username then show "That username is not correct!" otherwise show "That is a correct username!"
$this->username brings the variable $username
$this->c_username brings the variable $c_username.
Now save that as username_class.php
Here is how to use it:
<?php
include "username_class.php"; // Includes class.
$username = new check_username; // Starts the class, check_username is the name we started earlier.
$username->c_username = "Caleb"; // Username to check against.
$username->username = "Bob"; // Username to check.
?>
Comments should help.
Thanks,
Caleb!
Required knowledge:
Basic knowledge of PHP.
Functions.
Lets begin, you know to tell apache to enter PHP mode we need to enter the PHP syntax:
<?php
?>
Lets start to build our class, we are going to make a "check username" class.
First we need to declare that this is going to be a class:
<?php
class check_username
{
}
?>
class - tells PHP this is a class
check_username is the name of the class used later in this tutorial.
Lets begin with a VAR. It is a variable, just like $bob is a variable.
<?php
class check_username
{
var $username;
}
?>
Now, lets begin our "check username" function:
<?php
class check_username
{
var $username;
function check()
{
}
}
?>
That declares that we are ready for a function. Lets add a little to the function to check the username. We need a username to check against so lets add another variable.
<?php
class check_username
{
var $username;
var $c_username;
function check()
{
}
}
?>
Now lets make it check the username:
<?php
class check_username
{
var $username;
var $c_username;
function check()
{
if ($this->username != $this->c_username)
{
echo "That username is not correct!";
}
else
{
echo "That is a correct username!";
}
}
}
?>
if($this->username != $this->c_username)
if the variable $username does not equal the variable $c_username then show "That username is not correct!" otherwise show "That is a correct username!"
$this->username brings the variable $username
$this->c_username brings the variable $c_username.
Now save that as username_class.php
Here is how to use it:
<?php
include "username_class.php"; // Includes class.
$username = new check_username; // Starts the class, check_username is the name we started earlier.
$username->c_username = "Caleb"; // Username to check against.
$username->username = "Bob"; // Username to check.
?>
Comments should help.
Thanks,
Caleb!