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 9 of 9
  1. #1
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default What is the best "method" to code PHP.

    Righty, say you have a code, which would you say is the cleanest coded, which one would you say is the best to look at, and which would / do you code like.

    Example 1 (My style of coding):
    PHP Code:
    <?php
    if(isset($_POST["username"]) && isset($_POST["password"]))
    {
            if(
    $_POST["username"] == "")
            {
                    do 
    this
            
    }
            else
            {
                    do 
    this
            
    }
    }
    ?>
    Example 2
    PHP Code:
    <?php
    if(isset($_POST[username]) && isset($_POST[password]))
    {if(
    $_POST[username] == "")
    {do 
    this}
    else
    {do 
    this}}
    ?>
    Example 3
    PHP Code:
    <?php
    if(isset($_POST['username']) && isset($_POST['password']))
    {
    if(
    $_POST['username'] == "")
    {        do 
    this
    }
    else
    {        do 
    this
    }
    }
    ?>


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  2. #2
    Join Date
    Dec 2006
    Location
    England
    Posts
    341
    Tokens
    0

    Default

    I'd say the first method as it looks better cleaner, and the rest look confusing, although it's the same code.
    Last edited by ?php?; 24-01-2007 at 01:46 PM.

  3. #3
    Join Date
    Dec 2005
    Location
    Australia
    Posts
    693
    Tokens
    0

    Default

    1, by far.

    Then use OOP.
    XHTML, CSS, AJAX, JS, php, MySQL.

    --

    HxF moderators can't read timestamps.

  4. #4
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    if(isset($_POST['u'], $_POST['p']) && !empty($_POST['u'])) foo();
    else 
    bar(); 
    kinda quit.

  5. #5
    Join Date
    Jul 2005
    Location
    Bristol
    Posts
    2,054
    Tokens
    -10

    Latest Awards:

    Default

    Josh!



    Long time no see.

  6. #6
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by nets View Post
    PHP Code:
    if(isset($_POST['u'], $_POST['p']) && !empty($_POST['u'])) foo();
    else 
    bar(); 
    "eww"
    6ewws


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  7. #7
    Join Date
    Jan 2007
    Location
    West Yorkshire
    Posts
    384
    Tokens
    0

    Default

    The first one, its cleaner and more organised.

    “two players, two sides.
    one is light, one is dark.”
    - John Locke

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

    Latest Awards:

    Default

    Quote Originally Posted by Heinous View Post
    1, by far.

    Then use OOP.
    I can agree with pretty much all of this, although unluckily full oop capability's have only come around in php5, so your somewhat limited in 4 and below "/

    nets: That doesn't really look cleaner, its more efficient, but not as obvious or clear as the previous two.
    Plus i belive php may take issue with it, since your if is on one line, and the else is not, hence php may(in my recent experience (not actually in php though)) treats the else as part of a different statement, so youd need the else on the line with the if in order for your method to work, would you not?

  9. #9
    Join Date
    Aug 2004
    Location
    bristol
    Posts
    3,799
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by 01101101entor View Post
    I can agree with pretty much all of this, although unluckily full oop capability's have only come around in php5, so your somewhat limited in 4 and below "/

    nets: That doesn't really look cleaner, its more efficient, but not as obvious or clear as the previous two.
    Plus i belive php may take issue with it, since your if is on one line, and the else is not, hence php may(in my recent experience (not actually in php though)) treats the else as part of a different statement, so youd need the else on the line with the if in order for your method to work, would you not?
    It shouldn't be a problem, although if you've got multiple statements you'd need to encapsulate the code within curly braces. I believe you'd get an error if you used the OR operator after a semi-colon, however.

    PHP Code:
    $foo $bar OR exit;
    $foo $bar; OR exit; //error 
    kinda quit.

Posting Permissions

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