The guys do not know inheritance?

Discussion in 'PHP' started by kaiquej, Aug 27, 2009.

  1. #1
    I have seen some class written as follows:

    1-
    
    class MyDB extends mysqli
    {
         ..
        .....
        public function __construct()
        {
                .....
                [B]@mysqli_real_connect[/B](
                    $this->_host,
                    $this->_username,
                    $this->_password,
                    $this->_dbname
                );
    
        }
    }
    
    Code (markup):
    If you are using inheritance, why not do so?

    2-
    
    class MyDB extends mysqli
    {
        public function __construct()
        {
            [B]parent::[/B]real_connect(
                $this->_host,
                $this->_username,
                $this->_password,
                $this->_dbname
            );
        }
    }
    
    	
    
    Code (markup):
    What is the most elegant way to write? The first or second? Why?


    Thanks
     
    kaiquej, Aug 27, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not sure if you'd even need parent:: if its an inherited class, since the function is assumed to exist as is. (and only reason to do the first is in case you want to change the way the function works.)
     
    kblessinggr, Aug 27, 2009 IP