>
> You could go the other way though, and exploit this behaviour to force
> SCA to be deferred.

Interesting idea, so I thought I'd try it.  I had my SCA class
implement an empty interface, and sadly, it made no difference.  The
call to the static SCA::initComponent method is after the definition
of the SCA class and I think that is sufficient for the SCA class to
be defined irrespective of whether or not there is an interface.  If I
move the SCA::initComponent to before the SCA class definition then I
get a class not found fatal error for the SCA class.

Is this what you were suggesting, or have I missed the point?

Graham.

On 11 Sep, 11:28, Caroline Maynard <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to