sbwerewolf / json-serialize-trait
一个库,具有在调用 json_encode() 时输出类示例所有属性的特性
v1.0.2
2024-06-15 10:05 UTC
Requires
- ext-json: *
This package is auto-updated.
Last update: 2024-09-15 10:50:56 UTC
README
一个库,具有在调用 json_encode() 时输出类示例所有属性的特性
如何安装
composer require sbwerewolf/json-serialize-trait
如何使用
要使用 JsonSerialize,应在类中声明 use 语句
use \SbWereWolf\JsonSerializable\JsonSerializeTrait;
示例
class TraitTest implements JsonSerializable { /* Declaration of trait use */ use \SbWereWolf\JsonSerializable\JsonSerializeTrait; /* Declaration of class properties */ private $privateProp = 'privateProp'; protected $protectedProp = 'protected property value'; public $publicProp = 'public class member'; } /* Convert class-exemplar to JSON */ echo json_encode(new TraitTest(),JSON_PRETTY_PRINT); /* { "privateProp": "privateProp", "protectedProp": "protected property value", "publicProp": "public class member" } */
联系方式
Volkhin Nikolay
e-mail ulfnew@gmail.com
phone +7-902-272-65-35
Telegram @sbwerewolf
通过消息应用与我聊天