robbyc Posted January 31, 2007 Share Posted January 31, 2007 Hi can anyone help me possibly with an example. I want to define methods AS WELL AS private class variables/properties which must be implemented by sub classes the class variables are particularly important. Is this possible using an interface? all the documentation I read seems unclear. Or is it not possible to define variables that must be implemented in sub classes? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/36527-solved-interface-help/ Share on other sites More sharing options...
trq Posted January 31, 2007 Share Posted January 31, 2007 You could use an interface. <?php interface foo { private a; private b; public function geta(); } class bar implements foo { private a = "this is a"; private b = "this is b"; public function geta() { return $this->a; } } ?> Or.... If you would like to implement some of the functionality within your interface you could use abstraction. <?php abstract class foo { private a = "this is a"; private b = "this is b"; abstract public function geta(); } ?> Link to comment https://forums.phpfreaks.com/topic/36527-solved-interface-help/#findComment-173972 Share on other sites More sharing options...
robbyc Posted February 1, 2007 Author Share Posted February 1, 2007 Hi yeah have sorted my problem now. I realised that I don't want to define member variables (which you can't using interfaces anyway) as they should really be accessed through get and set methods. Thanks Link to comment https://forums.phpfreaks.com/topic/36527-solved-interface-help/#findComment-174515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.