Question: I've been working on code that's intended to be used with objects, without really caring what the kind of object is. I wanted to type hint that the method being written expected an object of any type, but ran into some difficulty. 

I tried `function myFunc (object $obj)` and `function myFunc (stdClass $obj)` but both of these generated errors when I tried to pass objects in: 

> 
> Catchable fatal error: Argument 1 passed to MyClass::MyFunc() must be an instance of object, instance of ObjectActualClass given
> 
> 
> 

The same happened with `stdClass` as well

What am I missing? I thought that all classes that didn't explicitly inherit from another class inherited from `stdClass`, meaning that the base class of every class in PHP would be `stdClass`. Is this not the case?

Answer: 
stdClass is NOT a base class! PHP classes do not automatically inherit from any class. All classes are standalone, unless they explicitly extend another class. PHP differs from many object-oriented languages in this respect.
Well it only took eight years, but this will soon be possible: PHP 7.2 introduces the `object` type hint! ~~As I write this, it's currently in the RFC stage, and [is due to be released in November](https://wiki.php.net/todo/php72).~~

**Update, 30th November:** [PHP 7.2 has been released](http://news.php.net/php.internals/101207)

[RFC: Object typehint](https://wiki.php.net/rfc/object-typehint)

[Discussion](https://externals.io/message/97135)

This behaves exactly as you might expect:

```
<?php

class Foo {}
class Bar {}

function takeObject(object $obj) {
    var_dump(get_class($obj));
}

takeObject(new Foo);
takeObject(new Bar);
takeObject('not an object');

```

Will result in:

> 
> string(3) "Foo"
> 
> 
> string(3) "Bar"
> 
> 
> Fatal error: Uncaught TypeError: Argument 1 passed to takeObject() must be an object, string given, called in...
> 
> 
> 

See <https://3v4l.org/Svuij>

One side-effect of this is that [`object` is now a reserved word](http://php.net/manual/en/reserved.other-reserved-words.php), which unfortunately renders @Gaz\_Edge's existing solution above [broken](https://3v4l.org/t2HHV). Fortunately, all you have to do to fix it is delete the interface.