Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the PHP variable handling function, serialize()

First off I've read the PHP manual, I've tested it out. Second I still don't understand what it really does? Why would I want to serialize a variable?

like image 473
Aaron Avatar asked May 09 '26 21:05

Aaron


1 Answers

You probably wouldn't want to serialise a variable as such, but it is useful to serialise objects and other complex data structures.

Instead of creating a database table with loads of columns, create a table with a primary key and a blob and serialise a class or array into it. That way you have an infinitly flexible system where if you need to add new data to the database table you don't have to add more columns.

This is one silly example, but persisting objects into a database is seriously useful if you think about it.

like image 168
Adam Pointer Avatar answered May 11 '26 12:05

Adam Pointer