-2

When i implemented an interface in a class and executed the code, it appeared the following error:


Fatal error: Interface 'IConn' not found in C:\xampp\htdocs\aulaPHP\SoNet\php_oo\OO_advanced\code_03_class_conn\Conn.php on line 3

The problem in this is that all the files are correctly placed, together, but the Interface cannot be found at the "Conn" file. Here's the code:


<?php 

class Conn implements IConn
{
    private $dsn;
    private $user;
    private $pass;

    public function __construct($dsn, $user, $pass)
    {
        $this->dsn = $dsn;
        $this->user = $user;
        $this->pass = $pass;
    }

    public function connect()
    {
        return new \PDO($this->dsn,$this->user,$this->pass);
    }
}

?>
tereško
  • 58,060
  • 25
  • 98
  • 150
Matt
  • 5
  • 2
  • 7
    do you use an autoloader ? If not, you're just missing a `require` statement here to the interface file – Calimero Oct 02 '17 at 20:58
  • 1
    I wasn't missing a require, but the require was after the class that it was being used by, making it "invisible". You helped anyway, thx! – Matt Oct 04 '17 at 20:07

1 Answers1

1

You are most likely missing arequire statement for the interface, if you are not using an autoloader.

Have a look at this answere about autoloading interfaces and abstract classes . I would also recommend you to consider composer, since it is one of the most common php dependency management tools, well documented and easy to use.

ju_
  • 569
  • 1
  • 4
  • 17
  • I wasn't missing a `require`, but the require was after the class that it was being used by, making it "invisible". You helped anyway, thx! – Matt Oct 03 '17 at 19:57