theophy/php-serializable

这有助于序列化PHP对象

1.0.0 2016-12-02 07:16 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:50:08 UTC


README

这有助于序列化PHP对象

如何使用

要使用它,调用名为serializable的静态方法,该方法将接收对象作为参数。以下是一个示例:

$user = new User();
$user->setFirstname("Theophilus");
$user->setLastname("Omoregbee");

$user->setStates(array(new State("Edo state", "ED"), new State("Lagos State", "LG")));
$user->setCountry(new Country("Nigeria","NG"));

$user->setRoles(array("ADMIN","DB MANAGER"));

$user->setEmail("theo4u@ymail.com");
$user->setPassword("1111");

//lets serialize our object now
echo json_encode(SerializeMe::serialize($user));

这将导致以下输出 {"firstname":"Theophilus","lastname":"Omoregbee","states":[{"name":"Edo state","code":"ED"},{"name":"Lagos State","code":"LG"}],"country":{"name":"Nigeria","code":"NG"},"dateCreated":1477351778,"roles":["ADMIN","DB MANAGER"],"email":"theo4u@ymail.com","password":"b59c67bf196a4758191e42f76670ceba"}

Response Json

贡献

允许贡献使其更快且可重用