Graham Charters wrote: > I've just created the test case and reproduced the behaviour (I won't > say "problem" because I think perhaps what we recommend today might be > the real problem). I tried something which I thought I'd already > attempted and it worked. So here's the explanation. > > It seems having interfaces changes when the class gets defined. We > currently suggest the following code layout for a service > implementation: > > /* includes for anything the service impl requires */ > include 'stuff.php'; > > // this must be the last include > include 'SCA/SCA.php'; > > class MyService {} > > This all works fine. SCA::initComponent(...) runs in the include of > SCA.php and it tests for class_exists('MyService'); and finds that it > does exist. > > The problem comes when we add an interface, as shown below: > > /* includes for anything the service impl requires */ > include 'stuff.php'; > > // this must be the last include > include 'SCA/SCA.php'; > > interface MyServiceInterface {} > > class MyService implements MyServiceInterface {} > > In the above example, the test for class_exists('MyService') fails. > get_declared_classes() confirms it doesn't exist and > get_declared_interfaces() shows that the interface does exist. The > simple/obvious fix, which I thought I'd tried last week, but clearly > hadn't is to move the include after the class declaration, as follows: > > /* includes for anything the service impl requires */ > include 'stuff.php'; > > interface MyServiceInterface {} > > class MyService implements MyServiceInterface {} > > // this must be the last include > include 'SCA/SCA.php';
It's good that you've got this to work now. Are you concluding that this is a "documentation error", and we should just modify the instructions and examples for how to include SCA? I can't see an alternative. This is a consequence of the php internals design, in that a derived class (whether by extending a base class or implementing an interface) is not processed at compile-time. So $my_foobar = new FooBar(); class FooBar {} is fine. But $my_bar = new Bar(); interface Foo {} class Bar implements Foo {} fails. You have to reorder it thus: interface Foo {} class Bar implements Foo {} $my_bar = new Bar(); I can't see a way round this (other than to submit a patch for the engine :-) ) - there's no way to force Bar to processed at compile time. You could go the other way though, and exploit this behaviour to force SCA to be deferred. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "phpsoa" group. To post to this group, send email to phpsoa@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.co.uk/group/phpsoa?hl=en -~----------~----~----~----~------~----~------~--~---