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

נכתב בתאריך כ"ו בכסלו ה'תשע"ב (יום חמישי, דצמבר 22nd, 2011) כ"ו בכסלו ה'תשע"ב (3:31 pm) בנושא

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

You might also be interested in
תגים:

הוסף תגובה

כתיבת תגובה

הוספת תגובה

Top