Type hinting for any object

后端 未结 9 1637
梦毁少年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:20

    You could do something like this:

    function myFunc ($obj)
    {
         if ($obj instanceof stdClass) { .... }
    }
    

提交回复
热议问题