Jump to content

[SOLVED] interface help :(


sasori

Recommended Posts

i creadted this test script and saved as interface.dbdriver.php

 

<?php

/**
* @author rmbapc
* @copyright 2008
*/
//interfaced.dbdriver.php
interface DBDriver
{
public function connect();
public function execute($sql);
}
?>

 

and then i created another file and saved as class.mysqldriver.php

<?php

/**
* @author rmbapc
* @copyright 2008
*/
//class.mysqldriver.php
include("interface.dbdriver.php");
class MySQLDriver implements DBDriver
{

}

?>

 

i tried to run the class.mysqldriver.php and the error says

 

Fatal error: Class MySQLDriver contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (DBDriver::connect, DBDriver::execute) in C:\wamp\www\test2\oop\class.mysqldriver.php on line 12

 

now my question is, "why does the error says, 2 abstract methods?" when infact i made an interface and not an abstract right?

Link to comment
https://forums.phpfreaks.com/topic/118867-solved-interface-help/
Share on other sites

In order for an interface to work, you must provide an implementation of every method in the interface in any class that implements it. >_>  Basically MySQL driver NEEDS a connect() and execute($sql) method of equal or greater visibility.

 

ok cool..very well said. thanks  :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.