phpphp-parse-error

Can a class extend both a class and implement an Interface


Can a class extend both an interface and another class in PHP?
Basically I want to do this:

interface databaseInterface{
 public function query($q);
 public function escape($s);
 //more methods
}

class database{ //extends both mysqli and implements databaseInterface
 //etc.
}

How would one do this, simply doing:

class database implements databaseInterface extends mysqli{ 

results in a fatal error:

Parse error: syntax error, unexpected T_EXTENDS, expecting '{' in *file* on line *line*

Solution

  • Try it the other way around:

    class database extends mysqli implements databaseInterface { ...}
    

    This should work.