PHP interface implementation rejects subclasses on parameters?

Class C implements I means that there must be subtype relation between C and I It means object of type C should be usable wherever an object of type I is required In your case C is more restrictive than I because it has more precise requirements on its doSomething argument I. DoSomething is fine with any A but C. DoSomething requires a specific subtype of A Note that if you change C.

DoSomething to accept any A then nothing prevents you to pass it an object of type B You just can't require only B because then you would break subtyping contract In theory, subtypes can be more liberal about their function arguments and more specific about their return types (but never vice versa, as it was in your case). In practice, a programming language may require that argument types in overridden methods must be same everywhere.

Class C implements I means that there must be subtype relation between C and I. It means object of type C should be usable wherever an object of type I is required. In your case C is more restrictive than I because it has more precise requirements on its doSomething argument -- I.

DoSomething is fine with any A but C. DoSomething requires a specific subtype of A Note that if you change C. DoSomething to accept any A then nothing prevents you to pass it an object of type B.

You just can't require only B, because then you would break subtyping contract. In theory, subtypes can be more liberal about their function arguments and more specific about their return types (but never vice versa, as it was in your case). In practice, a programming language may require that argument types in overridden methods must be same everywhere.

The second paragraph of your answer explains everything I needed to know. Thanks. – fabio Jan 24 at 14:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions