Results 1 to 10 of 10
Threaded View
-
25th Jul 2010, 12:32 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.com[PHP] Interfaces
What are they?
Interfaces a block-less classes that are used to make sure other classes contain certain methods and structure, the reason we use these is so that when we have a set of classes in projects we make sure that no matter what the method will exists.
What do they look like?
Here is an example:
PHP Code:interface Sample
{
public function Method($value);
}
How there used
Whan you create a class you use the keyword "implements" to tell the class that its using an interface.
Example:
PHP Code:class MyClass Implements SomeInterface
{
}
Interface:
PHP Code:interface IDatabase
{
public function connect($host,$username,$password);
public function openDatabase($database);
public function query($query);
}
so for the classes now you can have multiple classes the inherit the structure from the interface.
MySql
PHP Code:class DBMySql implements IDatabase
{
private $Connection,$Query;
public function connect($host,$username,$password)
{
$this->Connection = mysql_connect($host,$username,$password,true);
}
public function openDatabase($database)
{
mysql_select_db($database);
}
public function query($query)
{
return $this->Query = mysql_query($query);
}
}
PHP Code:class DBMySqli implements IDatabase
{
private $Connection,$Query;
public function connect($host,$username,$password)
{
$this->Connection = new MySqli($host,$username,$password,true);
}
public function openDatabase($database)
{
$this->Connection->select_db($database);
}
public function query($query)
{
return $this->Query = $this->Connection->query($query);
}
}
So usage lets say
PHP Code://MySql
$DBMySql = new DBMySql ();
//MySqli
$DBMySqli = new DBMySqli();
//No matter witch one i use they would always have the same functions, so $DBMySql->connect does the same thing as $DBMySqli->connect, apart from it uses different inner logic...
//BUT THEY WILL ALLWAYS BE THE SAME TO THE USER.
litewarez Reviewed by litewarez on . [PHP] Interfaces What are they? Interfaces a block-less classes that are used to make sure other classes contain certain methods and structure, the reason we use these is so that when we have a set of classes in projects we make sure that no matter what the method will exists. What do they look like? Here is an example: interface Sample Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...