get_object_vars() vs. cast to array

前端 未结 3 995
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 09:41

Are there any differences between get_object_vars($obj) and (array) $obj ?

Both seem to return the public properties of the object.

3条回答
  •  有刺的猬
    2020-12-08 10:21

    Better is what is what you actually need. get_object_vars() doesn’t show private and protected members. See this comment in the manual for an example.

提交回复
热议问题