Hi all
I'm attempting to train myself to code in an OOP way with PHP5. Been working through the PHP.net tutorial and also O'Reilly's Upgrading to PHP5.
Problem: my extension of an abstract class produces a fatal error and I cannot see why. There may be other stupid errors in the code, but I want to know the reason for the fatal error. Here's the abstract class:
abstract class AbsDatabase { //Abstract class defining the methods required in a DB class
abstract public function connecting();
abstract public function query();
abstract public function fetch();
abstract public function closing();
}
And here's the extension:
// Enable PHP5 to load class file on the fly
function __autoload($class_name) {
require_once("classlib/$class_name.php");
}
class MySQLi_norman extends AbsDatabase {
protected $dbh;
protected $query;
public $result;
public function connecting($server, $user, $password, $db)
{
$this->dbh = mysqli_connect($server, $user, $password, $db);
}
public function query($sql)
{
$this->query = mysqli_query($this->dbh, $sql);
}
public function fetch()
{
$this->result = mysqli_fetch_array($this->query, MYSQLI_NUM);
return $this->result;
}
public function closing()
{
mysqli_close($this->dbh);
}
}
// Now test it ...
$db_test = new MySQLi_norman;
$db_test->connecting("localhost", "root", "password", "test");
$db_test->query("SELECT name FROM php_test");
$string = $db_test->fetch();
echo "<html><head><title>Mysqli test</title></head><body>My dad's name is: ";
printf("%s", $string[0]);
echo "<br /></body></html>";
// And so on ...
And here's the fatal error:
Fatal error:
Declaration of MySQLi_norman::connecting()
must be compatible with that of
AbsDatabase::connecting() in
/usr/local/apache2/htdocs/general_test/abstract_class_use.php on line 15
Any pointers much appreciated.
Norm