Type hinting for any object

后端 未结 9 1655
梦毁少年i
梦毁少年i 2020-12-14 05:43

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 ex

9条回答
  •  醉酒成梦
    2020-12-14 06:09

    As of php 7.2 this feature has now been implemented. you can type hint for any object now.

    function myFunc(Object $myObject) : Object {
        return $myObject;
    }
    

    You can review this in the official documentation

提交回复
热议问题