Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default [TUT] PHP Classes & Functions

    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 Code:
    <?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!

    PHP Code:
    function my($mum$likes$you)

    That defines the functions name, and what variables to use in it

    PHP Code:
    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

    PHP Code:
    echo $mum;
    echo 
    $likes;
    echo 
    "<br />";
    echo 
    $you
    Echos the variables in the functions

    PHP Code:
    }
    }

    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 Code:
    <?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.
    Last edited by Nick-; 27-05-2007 at 10:08 AM.

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    Ok tutorial, although really random and useless example function lol.

  3. #3
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by 01101101entor View Post
    Ok tutorial, although really random and useless example function lol.
    I wanted to see if people could make sence out of the = "wordshere" and the $wordshere

  4. #4
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Even though I understand how to use both it was hard to follow.

  5. #5
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Quote Originally Posted by Luckyrare View Post
    Even though I understand how to use both it was hard to follow.
    What you mean..

  6. #6
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    What you mean..
    Coding tutorials need loads of comments in them, explaining what everything does. Plus a more realistic use would be better for the final example.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •