This is also a clear example of why hinting is a paint in the neck, and also why it is just developer paranoia to use them (to restrict flexibility in case of the unfathomable horror of someone making a mistake.)
Sorry but I didn't find that example *really* conducive to my example.
So what has this got to do with PHP type hinting? A lot. Given PHP is copying this type of hinting.
I'm not sure I understand the problem clearly or how it pertains to my own example, but, generics are similar to C++ templates. Templates attempt to give a strictly typed language some dynamic ability, by making types 'generic'.
Something like the adapter/provider relationship in a DB abstraction layer. You implement a stack object as a template, and inject (for lack of a better word -- this is not accurate at least not in C++) the type you want that stack to assume, so if you wanted to store a list of integers, you might:
Likewise one might do something like:
I wouldn't say PHP is copying this type of behavior, on the contrary PHP intrinsically supports this type of behavior, in fact, you must work in reverse of what PHP does by default by using a 'type-hint'.
I do not understand the problem example you provided well enough to comment further, but it sounds like the issue was being caused by the stricter type enforcement in languages like C# or .NET languages offer...
I think generics and type-hinting are quite different, enough so, that it is unfare to compare them.
Type-hinting (technically) simply triggers an error when you attempt to pass a function parameter the wrong 'type' (a safety net and nothing more) -- whereas generics do much more, as I described above.
I can successfully mock any object which I pass to a function in my own code, so long as the mock is derived from the base type or the actual argument 'type' everything should go as planned...
Cheers,
Alex