Blob
26-05-2007, 09:29 PM
Ok, well I was bored and decided to write this.
Classes are mainly used when you have lots of functions doing stuff for the same thing, e.g. you might have functions which displays the users level, username etc, so instead of indivitual ones you can group them together in a class.
Lets learn about functions:
Functions are used to make up your own functions hidden away in a file so no one looks at your rubbish coding and only see a good function (well for me it is..)
Anyway, in your function you can use allready made functions like this:
<?php
function my($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
my("is", "your", "lover");
?>
Lets split it down!
function my($mum, $likes, $you)
{That defines the functions name, and what variables to use in it
if($mum == "is" && $likes = "your" && $you == "lover")
{If your using functions you should know what it does, but it uses the variables defined in the function
echo $mum;
echo $likes;
echo "<br />";
echo $you;Echos the variables in the functions
}
}
my("is", "your", "lover");Ends the function and the if, and uses the functions.
Ok, now onto classes:
If you had multiple functions (these will just be the same)
You would do this:
<?php
class mum
{
function my($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
function ha($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
}
$any variable name here = new classnamehere(mum in our case)();
$the same variable as above->functionname("is", "your", "lover");
$the same variable as above->functionname("is", "your", "lover");
// So it would be:
$example = new classnamehere(mum in our case)();
$example->my("is", "your", "lover");
$example->ha("is", "your", "lover");
?>
I dont really need to explain it, as if you know PHP and are using classes you would understand it.
Edited by Nick- (Forum Super Moderator): Thread moved from Website Designing.
Classes are mainly used when you have lots of functions doing stuff for the same thing, e.g. you might have functions which displays the users level, username etc, so instead of indivitual ones you can group them together in a class.
Lets learn about functions:
Functions are used to make up your own functions hidden away in a file so no one looks at your rubbish coding and only see a good function (well for me it is..)
Anyway, in your function you can use allready made functions like this:
<?php
function my($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
my("is", "your", "lover");
?>
Lets split it down!
function my($mum, $likes, $you)
{That defines the functions name, and what variables to use in it
if($mum == "is" && $likes = "your" && $you == "lover")
{If your using functions you should know what it does, but it uses the variables defined in the function
echo $mum;
echo $likes;
echo "<br />";
echo $you;Echos the variables in the functions
}
}
my("is", "your", "lover");Ends the function and the if, and uses the functions.
Ok, now onto classes:
If you had multiple functions (these will just be the same)
You would do this:
<?php
class mum
{
function my($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
function ha($mum, $likes, $you)
{
if($mum == "is" && $likes = "your" && $you == "lover")
{
echo $mum;
echo $likes;
echo "<br />";
echo $you;
}
}
}
$any variable name here = new classnamehere(mum in our case)();
$the same variable as above->functionname("is", "your", "lover");
$the same variable as above->functionname("is", "your", "lover");
// So it would be:
$example = new classnamehere(mum in our case)();
$example->my("is", "your", "lover");
$example->ha("is", "your", "lover");
?>
I dont really need to explain it, as if you know PHP and are using classes you would understand it.
Edited by Nick- (Forum Super Moderator): Thread moved from Website Designing.