Pain Posted February 7, 2014 Share Posted February 7, 2014 (edited) Hello. Im starting to understand about interfaces a bit, however I can't seem to get them working. So i figured i'd go here and ask a few questions. This is my class programming.php <?php class Programming implements Intfac { public function sayHello() { echo 'Just Hello'; } public function sayBye() { echo 'Bye'; } } ?> This is my interface intfac.php <?php interface Intfac { public function sayHello(); public function sayBye(); } ?> How do I run the interface now? <?php require('class/programming.php'); require('interface/intfac.php'); $programming = new Programming; ?> Thanks:) Edited February 7, 2014 by Pain Quote Link to comment Share on other sites More sharing options...
.josh Posted February 8, 2014 Share Posted February 8, 2014 You aren't supposed to "run the interface" directly. It's basically a blueprint. In practice, you'd do something like this: $foobar = new Programming(); $foobar->sayHello(); $foobar->sayBye(); The idea here is that if you did not define sayHello() and sayBye() in Programming, you'd get an error. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 8, 2014 Share Posted February 8, 2014 Don't implement sayHello() or sayBye() in your Programming class and see what happens. The result you get is one of the main advantages to interfaces. Quote Link to comment 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.