TJMAudio Posted October 10, 2006 Share Posted October 10, 2006 Then I was browsing php.net. I came across some function, I forget what it was, but then it contained a very complex, almost C# looking, PHP script. I was just wondering what it did? Mainly one function it used a lot, and that was "interface". Here is the script:[code]<?phpinterface INamed{ public function getName();}interface ISon{ public function getFather();}interface IFather{ public function getSons();}abstract class Named implements INamed{ protected $name; public function __construct($name) { $this->name = $name; } public function __destruct() {} public function getName() { return $this->name; }}abstract class Son implements ISon{ protected $father; public function getFather() { return $this->father; } public function __construct(IFather $father = null) { $this->father = $father; } public function __destruct() {}}abstract class Father implements IFather{ protected $sons = array(); public function getSons() { return $this->sons; } public function __construct($sons = array()) { $this->sons = $sons; } public function __destruct() {}}class Man implements INamed, ISon, IFather{ public function __construct($name, IFather $father = null, $sons = array()) { // note: these are just __construct() calls - not real class initializations Named::__construct($name); Son::__construct($father); Father::__construct($sons); } public function __destruct() { Named::__destruct(); Son::__destruct(); Father::__destruct(); } public function getFather() { return Son::getFather(); } public function getSons() { return Father::getSons(); } public function getName() { return Named::getName(); }}$siarhej = new Man('Siaroh', new Man('Adas'), array(new Man('Seva')));var_dump($siarhej->getName());var_dump($siarhej->getFather()->getName());$siarhejSons = $siarhej->getSons();var_dump($siarhejSons[0]->getName());?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/23496-so-i-was-just-reading-phpnet/ Share on other sites More sharing options...
Daniel0 Posted October 10, 2006 Share Posted October 10, 2006 Interfaces are sort of like templates for classes (PHP5 or higher only). When a class implements an interface, then it must contain the elements that the interface contains.[url=http://php.net/manual/en/language.oop5.interfaces.php]More info on interfaces[/url] Quote Link to comment https://forums.phpfreaks.com/topic/23496-so-i-was-just-reading-phpnet/#findComment-106641 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.