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: 
Although there is no type hinting for objects, you can use:

```
if (!is_object($arg)) {
    return;
}

```
Typehint for `stdClass` works since PHP 5.3+ (if I am not wrong).
Following is valid code using typehint for `stdClass` construct:

Example `test.php`:

```
class Test{
    function hello(stdClass $o){
        echo $o->name;
    }
}

class Arg2 extends stdClass{
    public $name = 'John';
    function sayHello(){
        echo 'Hello world!';
    }
}

$Arg1 = new stdClass();
$Arg1->name = 'Peter';

$Arg2 = new Arg2();
$Arg2->sayHello();

$test = new Test();

// OK
$test->hello($Arg1);
$test->hello($Arg2);

// fails
$test->hello(1);

```

Prints out:

> 
> Hello world!  
> 
>  Peter  
> 
>  John
> 
> 
> Catchable fatal error: Argument 1 passed to Test::hello() must be an instance of stdClass, integer given, called in test.php on line 32 and defined in test.php on line 5
> 
> 
>