unserialize

$this->txndata = unserialize($d['data']);

what does unserialize mean
LVL 1
rgb192Asked:
Who is Participating?
 
Ray PaseurCommented:
Sample code to show how each is used...

best regards, ~Ray
<?php // RAY_serialize_unserialize_2.php
error_reporting(E_ALL);
echo "<pre>";

// MAN PAGE: http://us3.php.net/manual/en/function.unserialize.php
// MAN PAGE: http://us3.php.net/manual/en/function.serialize.php

// CREATE AN ARRAY
$old = array();

// ADD TWO THINGS TO THE ARRAY
$old["uid"] = 'Ray';
$old["pwd"] = 'Paseur';

// SHOW THE ARRAY
var_dump($old);

// SERIALIZE THE ARRAY
$string = serialize($old);

// SHOW THE SERIALIZED ARRAY
var_dump($string);

// UNSERIALIZE THE STRING INTO A NEW ARRAY
$new = unserialize($string);

// SHOW THE NEW ARRAY
var_dump($new);

// DOES THE BEFORE AND AFTER MATCH?
if ($new == $old) echo "\nMATCH!";

Open in new window

0
 
leakim971PluritechnicianCommented:
Imagine you need to return or pass a complex object for example passing an array (which contain multiple value) to another script or page , you use serialize the array.
Other side, when you receive an serialized object you need to unserialize it to use it.

$d['data'] represent/contain a serialized object and you put it unserialized version in the var $this->txndata
0
 
kumaranmcaCommented:
Greetings All,

serialize() and unserialize really great functions in PHP.

serialize()

serialize() returns a string containing a byte-stream  representation of value that can be stored anywhere.  
This is useful for storing or passing PHP values around without losing their  type and structure.  
To make the serialized string into a PHP value again, use unserialize(). serialize() handles all types, except the resource-type. You can even serialize()  arrays that contain references to itself. References inside the array/object you  are serialize()ing will also be stored.

When serializing objects, PHP will attempt to call the member function __sleep() prior to serialization. This is to allow the object  to do any last minute clean-up, etc. prior to being serialized. Likewise, when  the object is restored using unserialize() the __wakeup() member  function is called.

unserialize()

unserialize() takes a single serialized variable (see  serialize()) and  converts it back into a PHP value. The converted value is returned, and can be a  boolean, integer, float, string, array or object. In case the passed  string is not unserializeable, FALSE is returned and  E_NOTICE is issued.  Warning:  
FALSE is returned both in the case of an error  and if unserializing the serialized FALSE value. It  is possible to catch this special case by comparing str with serialize(false) or by  catching the issued E_NOTICE.  unserialize_callback_func directive:  
It's possible to set a callback-function which will be called, if an  undefined class should be instantiated during unserializing. (to prevent getting  an incomplete object "__PHP_Incomplete_Class".) Use your  php.ini, ini_set() or .htaccess to  define 'unserialize_callback_func'. Everytime an undefined class should be  instantiated, it'll be called. To disable this feature just empty this setting.  Also note that the directive unserialize_callback_func directive became  available in PHP 4.2.0.  
If the variable being unserialized is an object, after successfully  reconstructing the object PHP will automatically attempt to call the __wakeup() member function (if it exists).

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
kumaranmcaCommented:
Greetings

serialize():-  compares the array/text values in junk/encrypt format.

unserialize():-  Extract the encrypted/compress the array/text values.
0
 
rgb192Author Commented:
what could be an example of which each one is used

0
 
Ray PaseurCommented:
rgb192:  I am going to save you a million points here at EE.  You can find the descriptions of the functions on the PHP web site, along with examples and user-contributed notes.  It is one of the best online manuals in the history of computing.  See the man page here:

http://us3.php.net/manual/en/function.unserialize.php

How to learn about "serialize?"  Use the search box at the upper right of each page of the PHP.net online manual.

You should ALWAYS look up EVERY PHP function before you use it in your code.  No exceptions.
0
 
rgb192Author Commented:
after trying code, i think i understand
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.