> why does the engine care about the visibility of interface 
> methods I declare?
> I understand the argument that interface methods only have 
> 'meaning' when applied as public methods of objects - but 
> thats rather academic and personally I can think of useful 
> ways to abuse interfaces using protected methods at the very 
> least why am I not allowed to do this just because someone 
> decided that its not correct?

Having anything else than "public" in an interface simply does not make
any sense - an interface serves as a contract to external clients. It
guarantees them that there will be a set of methods they can call on an
object instance. What should be the semantic meaning of non-public
elements in interfaces?

> and given that I can implement a non-static method without 
> using $this or any other symbol/code related to the 
> instantiated object (effectively creating a static method) 
> which I can call using static notation why not allow static 
> interface methods?

As to static interface methods - same as above. An interface is an
interface :), not an implementation. So you will never have methods
implemented in an interface. The interface just says "the class
implementing the interface has a method named xy() that you can call".

So how would you make the static call on the interface?
ISomewhat::someMethod()? Where should that be implemented? This is why
you always need an instance that implements the interface and you make a
"normal" call on this instance. PHP allows - as opposed to C# or Java
(IIRC) - to call static methods on instances.

I think the fact that you can call nonstatic methods statically is BC
with "early days"; you don't want to do that in your code because it
will get you problems sooner or later. In "older" code you could not
mark methods as static, so the language could not check if a static call
is allowed. It simply permitted the call, not setting $this.

> also I noticed that using the keyword 'abstract' with a 
> interface method declaration is all of a sudden (5.1RC5dev) 
> causing a fatal error where before (5.0.2 - 5.0.4) no error 
> what so ever.

I thought I would never write anything like that - but: What sense does
"abstract" make in an interface at all?

You shouldn't have been writing "abstract" in an interface in the first
place. >:)

> If 'static', 'protected', 'private' are not allowed with 
> interfaces (very unpragmatic imho) then why the fatal errors? 
> why not an E_STRICT and just ignore those declaration... 

As I understand it, E_STRICT is for complaining about stuff like "var"
that was ok with PHP4 but is discouraged in PHP5. But you are using PHP5
elements in a way that make no sense to the language, so it's simply an
error.

> especially because not declaring a method static and leaving 
> off the visibility leaves you with a method that is 
> non-static and public - exactly what an interface 'requires'.

You're explicitly requesting something that is not possible - an fatal
error is the only thing that can be the result.

Matthias

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to