TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Using Interfaces (http://www.talkphp.com/advanced-php-programming/4290-using-interfaces.html)

Killswitch 05-15-2009 11:16 PM

Using Interfaces
 
This is something I have yet to touch on, interfaces and abstract classes, and need a bit of help using them. I understand their purpose and logic ( I think ).

I am working on a project that will allow users to buy addons for their website. This website is hosted and maintained by me, but it allows them to manage the data ( they can choose features they want, the template that is installed, etc ).

This is all ran on a component layer so I can easily add these features once they've paid for them ( and there will occasionally be some freebies ).

For the sake of leaving things open for development later ( maybe I will find the need to hire someone to help add new stuff ), I have decided that the component classes should follow a suit. The main admin index checks the required class file, auto instantiates the class ( if defined to do so ), passing important vars to the constructor and calling the performer method. It has a few other required things as well soon that will be sent around to other classes for stats and other things ( again, leaving it open, haven't implemented that yet ).

Basically, what I think I want to use for this is an interface. I have a seperate file for all interfaces ( components, plugins, and a few other things ). I have required the interface class, and in my component, component IMPLEMENTS interface_name.

What I am getting now is an error : interface components not found in file.php. Is there a special way to do this? Does the interface have to exist int he same file, or does it need to be called? I checked the manual, but their examples reside in the same file, which doesn't seem logical in my situation ( because I would have to repeat it over and over ).

Salathe 05-15-2009 11:46 PM

Quote:

Originally Posted by Killswitch (Post 24118)
What I am getting now is an error : interface components not found in file.php. Is there a special way to do this? Does the interface have to exist int he same file, or does it need to be called? I checked the manual, but their examples reside in the same file, which doesn't seem logical in my situation ( because I would have to repeat it over and over ).

The error means that the code is looking for an interface called components. Does the interface that you have defined have that name?

The interface needn't be in the same file as the class(es) which implements it but it does need to be included into the script at some point before the class definition.

Killswitch 05-16-2009 04:04 AM

Ok, never mind, I found the answer. I was requiring the interface after requiring the component file. I required component file, ran a few checks on that then included the interface only if we were supposed to auto instantiate the class, just so I wasnt requiring things I may not need, but can work around it now.

Thanks.


All times are GMT. The time now is 12:25 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0