PHP Classes
elePHPant
Icontem

Serialize: Automatic serialization of objects with getters

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2017-04-12 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 176 All time: 8,144 This week: 640Up
Version License PHP version Categories
serialiazable 1.0.4The PHP License5PHP 5, Language
Description Author

This class can perform automatic serialization of objects with getters.

It takes an object of a class and uses Reflection to extract the list of variables for which there is an explicit getter function.

The class calls all the object getter functions and returns a serialization of the object into a string in the JSON format.

Getter functions that return objects will be make this class also serialized the referenced objects recursively.

Innovation Award
PHP Programming Innovation award nominee
November 2016
Number 10


Prize: One downloadable copy of Komodo IDE
When you want save the information of an object you can use the serialize function or even the json_encode function.

However, these functions may generate serialized strings that contain much more information than you actually need to save.

This class provides a more efficient solution for saving only the relevant information of an object. It uses reflection to determine the name of the getter functions.

This way the class can retrieve only the values of the relevant class variables to save. It returns an object representation with their values in the JSON format.

Furthermore, getter objects that return other objects can be also serialized recursively.

Manuel Lemos
  Performance   Level  
Name: Theophilus Omoregbee <contact>
Classes: 1 package by
Country: Nigeria Nigeria
Age: 22
All time rank: 392826 in Nigeria Nigeria
Week rank: 1056 Up15 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 1x

Details

php-serializable

this helps to serialize php object

how to

to use it call the static method called serilaizable which will take in the obect as parameter. see example below


$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));

which will lead to this output {"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

Contributions

Allow contributions to make it faster and re-usable

Screenshots  
  • screenshot
  Files folder image Files  
File Role Description
Files folder image.idea (3 files, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Image file serializable.png Data Auxiliary data
Plain text file Serialize.php Class Class source

  Files folder image Files  /  .idea  
File Role Description
Files folder imagecopyright (1 file)
  Accessible without login Plain text file modules.xml Data Auxiliary data
  Accessible without login Plain text file php-serializable.iml Data Auxiliary data
  Accessible without login Plain text file vcs.xml Data Auxiliary data

  Files folder image Files  /  .idea  /  copyright  
File Role Description
  Accessible without login Plain text file profiles_settings.xml Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 90%
Total:176
This week:0
All time:8,144
This week:640Up