get_object_vars() vs. cast to array

前端 未结 3 1023
隐瞒了意图╮
隐瞒了意图╮ 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:11

    The get_object_vars() function is a clearer method of achieving the effect you want. Although casting it to an array is a solution as well, this behavior might change in later versions of PHP.

    I don't know if there is an actual difference between the two methods but the arguments above would lead me to use the function.

提交回复
热议问题