PHP Classes

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    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 181 All time: 8,666 This week: 213Up
Version License PHP version Categories
serialiazable 1.0.4The PHP License5PHP 5, Language


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
Picture of Theophilus Omoregbee
  Performance   Level  
Name: Theophilus Omoregbee <contact>
Classes: 1 package by
Country: Nigeria Nigeria
Age: 29
All time rank: 418237 in Nigeria Nigeria
Week rank: 388 Up11 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 1x



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->setStates(array(new State("Edo state", "ED"), new State("Lagos State", "LG")));
$user->setCountry(new Country("Nigeria","NG"));

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


//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":"","password":"b59c67bf196a4758191e42f76670ceba"}

Response Json


Allow contributions to make it faster and re-usable

  • 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 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  
This week:0
All time:8,666
This week:213Up