Beware of using an 'object' type hint in PHP function

Yedidia Klein

PHP 5 introduced Type Hinting for objects and since PHP 5.1 also for 'array', Type Hinting is a way for a function to restrict the types of the parameters to be passed to it. Since in PHP there is no "base" object for all objects we can't use type hint for getting just object but any object meaning the following will not work:

function(object $o) {
    //...
}

will actually throw for anything it will be called with.

--dhg

Binat Building Har Hotzvim Jerusalem 97787 St Natanzon 5/2 026310246 | 0526071135 | 0524767193 | sales@openapp.co.il