How do I json encode private properties in php?

后端 未结 4 1744
独厮守ぢ
独厮守ぢ 2020-12-21 01:29

I am working with doctrine 2 and zend framework 1.11. Public properties are discouraged in Doctrine 2, so I made my entity properties private. However I have just learned th

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-21 01:49

    Create a method how this in your class:

    function serialize(){
        return json_encode(get_object_vars ($this));
    }
    

提交回复
热议问题