drogo Posted December 17, 2009 Share Posted December 17, 2009 Hi Could someone give me some advice please. I'm playing around with interfaces and OOP PHP and I've set up an interface class and a class which implements it however when I run the script form the browser on my local server I get the following error: "Fatal error: Interface 'Chargeable' not found in C:\wamp\www\oop\class_ShopProduct.php on line 4" Here are the two classes: interface Chargeable { public function getPrice(); } class ShopProduct implements Chargeable { public function getPrice() { return 23; } } and the client code: include_once('./class_ShopProduct.php'); $np = new ShopProduct; echo $price = $np->getPrice(); I'm running Windows 7 with WAMP server 2.0 (PHP 5.3.0 & Apache 2.2.11) Any help would be appreciated as I can't work out how it's not working when it seems like it should. Quote Link to comment https://forums.phpfreaks.com/topic/185482-interface-not-found/ Share on other sites More sharing options...
rajivgonsalves Posted December 17, 2009 Share Posted December 17, 2009 where are you including the interface is it in the class file Quote Link to comment https://forums.phpfreaks.com/topic/185482-interface-not-found/#findComment-979259 Share on other sites More sharing options...
drogo Posted December 17, 2009 Author Share Posted December 17, 2009 no its in another file in the same folder called "interface.php": <?php include_once('./class_ShopProduct.php'); $np = new ShopProduct; echo $price = $np->getPrice(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185482-interface-not-found/#findComment-979262 Share on other sites More sharing options...
rajivgonsalves Posted December 17, 2009 Share Posted December 17, 2009 your code should be then <?php include_once('./interface.php'); include_once('./class_ShopProduct.php'); $np = new ShopProduct; echo $price = $np->getPrice(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185482-interface-not-found/#findComment-979267 Share on other sites More sharing options...
drogo Posted December 17, 2009 Author Share Posted December 17, 2009 thanks that works Quote Link to comment https://forums.phpfreaks.com/topic/185482-interface-not-found/#findComment-979268 Share on other sites More sharing options...
ignace Posted December 17, 2009 Share Posted December 17, 2009 I disagree it should be: require_once('Chargeable.php'); class ShopProduct implements Chargeable { public function getPrice() { return 23; } } Otherwise he will have to add include_once('interface.php'); everytime he wants to use the ShopProduct class Quote Link to comment https://forums.phpfreaks.com/topic/185482-interface-not-found/#findComment-979269 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.