Accessing private/protected properties of an object in anonymous function in PHP

后端 未结 3 1290
深忆病人
深忆病人 2021-01-13 11:36

I\'m trying to dump elements of an object\'s private property through an anonymous function - of course I could achieve this in any number of other ways, but this highlights

3条回答
  •  青春惊慌失措
    2021-01-13 12:08

    As you said yourself, it is private and therefore in accessible.

    You can:

    • Pass $this->payload as a parameter to the anonymous function.
    • Create a method in the class and use it instead.

提交回复
热议问题