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
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default PHP OO Inheritance

    I've seen people using inheritance in PHP two different ways, thought I imagine there is more.

    Like this:
    PHP Code:
    <?php

    public class NumberOne {}
    public class 
    NumberTwo extends NumberOne {}
    // Number two has access to NumberOne's members within scope
    ?>
    And this:
    [/php]
    <?php
    public class NumberOne {}
    public class NumberTwo {
    $this->two = new NumberOne;
    $this->two has access to NumberOne's members within scope
    }
    ?>
    [/php]

    Sorry for any syntax errors, but you get the idea.

    I'm coding a new application that is quite complicated, and was wondering how I should code my application?

    I've seen both of these in reasonably upscale code, so I presume it's OK with both.

    Could you list the pros and cons?

    Thanks,

    Charlie.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  2. #2
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    Oh gawd. I can't be bothered really but i'll explain one thing with the first method (using extends) - I believe you can only extend it once... meaning you may be stranded trying to access other classes etc...

    And please, please stop using technical knowledge - only because when you writing it, it seems so fake.


    www.fragme.co = a project.

  3. #3
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    Oh gawd. I can't be bothered really but i'll explain one thing with the first method (using extends) - I believe you can only extend it once... meaning you may be stranded trying to access other classes etc...

    And please, please stop using technical knowledge - only because when you writing it, it seems so fake.
    OK, anything else?

    Also, stop telling me that, I know what I'm saying when I say it. :/
    How could this hapen to meeeeeeeeeeeeeee?lol.

  4. #4
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    I'm just saying when your using that type of language it feels as though you are trying desperatly to be known as some coding god. I'm sure people understand where im coming from.


    www.fragme.co = a project.

  5. #5
    Join Date
    May 2007
    Posts
    467
    Tokens
    0

    Default

    Quote Originally Posted by Dentafrice View Post
    I usually pas on things like this, sort of like your 2nd example, but it has nothing to do with inheritance

    Here is an example:

    configuration:

    PHP Code:
    require_once "classes/core.php";

    $database ["server"] = "localhost";
    $database ["username"] = "";
    $database ["password"] = "";
    $database ["database"] = "";

    $core = new core( );
    $core->init$database ); 
    init in core:

    PHP Code:
        public function init($database) {
            
    $server $database ["server"];
            
    $username $database ["username"];
            
    $password $database ["password"];
            
    $databaseName $database ["database"];
            
            require_once 
    "classes/database.php";
            
    $database = new database( );
            
    $database->core = & $this;
            
            
    $this->database = & $database;
            
            
    /*
             * Define error types.
             */
            
            
    $this->errorType = array ();
            
    $this->errorType ["error"] = E_USER_ERROR;
            
    $this->errorType ["warning"] = E_USER_WARNING;
            
    $this->errorType ["notice"] = E_USER_NOTICE;
            
            
    /*
             * Connect
             */
            
    $database->init();
            
    $database->connectMySQL$server$username$password$databaseName );
        } 
    I set references to classes so, $this->database = & $database, $this->template = & $template.
    Why do you not define $database like

    PHP Code:
    require_once "classes/core.php";
    $database = array ( );
    $database ["server"] = "localhost";
    $database ["username"] = "";
    $database ["password"] = "";
    $database ["database"] = "";

    $core = new core( );
    $core->init$database ); 
    or is it pointless in doing that?

  6. #6
    Join Date
    Sep 2005
    Location
    East London
    Posts
    3,028
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    I'm just saying when your using that type of language it feels as though you are trying desperatly to be known as some coding god. I'm sure people understand where im coming from.
    Yeh, u talking about when he said sumthing about

    MySQLi or something?

  7. #7
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    I usually pas on things like this, sort of like your 2nd example, but it has nothing to do with inheritance

    Here is an example:

    configuration:

    PHP Code:
    require_once "classes/core.php";

    $database ["server"] = "localhost";
    $database ["username"] = "";
    $database ["password"] = "";
    $database ["database"] = "";

    $core = new core( );
    $core->init$database ); 
    init in core:

    PHP Code:
        public function init($database) {
            
    $server $database ["server"];
            
    $username $database ["username"];
            
    $password $database ["password"];
            
    $databaseName $database ["database"];
            
            require_once 
    "classes/database.php";
            
    $database = new database( );
            
    $database->core = & $this;
            
            
    $this->database = & $database;
            
            
    /*
             * Define error types.
             */
            
            
    $this->errorType = array ();
            
    $this->errorType ["error"] = E_USER_ERROR;
            
    $this->errorType ["warning"] = E_USER_WARNING;
            
    $this->errorType ["notice"] = E_USER_NOTICE;
            
            
    /*
             * Connect
             */
            
    $database->init();
            
    $database->connectMySQL$server$username$password$databaseName );
        } 
    I set references to classes so, $this->database = & $database, $this->template = & $template.
    Last edited by Dentafrice; 19-10-2008 at 12:36 AM.

  8. #8
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    The second example is not a example of inheritance.

  9. #9
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    Ok. Thanks guys. Source I understand what you are saying, but I'm just using that kind of language so it's easier to explain to people.
    How could this hapen to meeeeeeeeeeeeeee?lol.

Posting Permissions

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