PHP | unserialize() Function

PHP unserialize() is a builtin function in PHP7 which takes a single serialized variable and converts it back into a PHP value.

This feature seeks to provide better security when unserializing objects on untrusted data. It prevents possible code injections by enabling the developer to whitelist classes that can be unserialized.

Syntax:

Example #1 unserialize() example

Output:

a:3:{i:0;s:4:”Math”;i:1;s:8:”Language”;i:2;s:7:”Science”;}
array(3) { [0]=> string(4) “Math” [1]=> string(8) “Language” [2]=> string(7) “Science” }

Example #2 unserialize() example

Example #3 unserialize() example

Here’s a simple function to get the class of a serialized string (that is, the type of object that will be returned if it’s unserialized().

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers.