When should I use stdClass and when should I use an array in php oo code?

前端 未结 7 509
太阳男子
太阳男子 2020-11-29 00:33

In the middle of a period of big refactorings at work, I wish to introduce stdClass ***** as a way to return data from functions and I\'m trying to find non-subjectives argu

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 00:52

    Using stdClass to fulfill the same function as an array is not very useful IMHO, it just adds the overhead of an object without any real benefit. You're also missing out on many useful array functions (e.g. array_intersect). You should at least create your own class to enable type checking, or add methods to the object to make it worth using an object.

提交回复
热议问题