Quote Originally Posted by kyberfabrikken View Post
We are, but primitives have (implicit) interfaces too. For example, if a class implements __toString(), then objects of that class has the same interface as a primitive string has. If you restrict the contract of a function to the concrete type "string", then you are preventing the caller from passing an object that otherwise fulfils the contract. This leads to code with a lot of explicit type-juggling.
One would hope that the internals of the language would take care of handling all of this, i.e, if you say a parameter should be a string, and you pass an object that implements __toString(), it would treat it as a string.

Which brings up an interesting point which we can currently test to see if the language handles this with the array typehint and objects that implement ArrayAccess:

Code:
Macintosh:/ macbookpro$ php -a
Interactive shell

php > class Only_Wants_Arrays
php > {
php {     public function __construct(array $array) { }
php { }
php > 
php > $array = array(1,2,3,4,5);
php > $object = new ArrayObject($array);
php > $test = new Only_Wants_Arrays($object);

Catchable fatal error: Argument 1 passed to Only_Wants_Arrays::__construct() must be an array, object given, called in php shell code on line 1 and defined in php shell code on line 3
Macintosh:/ macbookpro$
And, it appears that it does not. And that, I would say, is a bug in the language, or at the very least that the implementation of ArrayAccess in the internals of the language is incomplete, because there are numerous areas where it works, i.e, where the object functions exactly as an array as expected.... so why not here too?