TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-15-2009, 12:11 AM   #1 (permalink)
The Contributor
 
planepixel's Avatar
 
Join Date: Feb 2009
Posts: 28
Thanks: 10
planepixel is on a distinguished road
Default what is php serialization

Hi
i came across php serialization but could not figure out what it is?i read php manual but did not get the point.

if somebody could throw some light about why and when we need to do serialization and what would happen if we do not do it?



thanks
planepixel is offline  
Reply With Quote
Old 07-15-2009, 01:48 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

It's basically the representation of an array as a string. Good for storing the contents of an array in a file, and then being able to rebuild it with ease.

Take the following as a good example. Here we're saving the array, and then reloading it. It will give us the array just how we had it when we created it initially.

php Code:
function TalkPHP_Array_Save($aMyArray)
{
    $szSerialize = serialize($aMyArray);
    file_put_contents('myArray.txt', $szSerialize);
}

function TalkPHP_Array_Load()
{
    $szSerialize = file_get_contents('myArray.txt');
    return unserialize($szSerialize);
}

$aFruit = array('Orange', 'Apple', 'Banana');

/* Save and unset the array. */
TalkPHP_Array_Save($aFruit);
unset($aFruit);

/* Reload the array from a serialized string. */
$aFruit = TalkPHP_Array_Load();
print_r($aFruit);
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 07-15-2009, 04:54 PM   #3 (permalink)
The Contributor
 
cecilia's Avatar
 
Join Date: May 2009
Location: LA, CA
Posts: 87
Thanks: 0
cecilia is on a distinguished road
Default

Isnt serialization used for converting an object into a string, allowing it to be stored on a database or passed by POST or GET?

At the moment, ive been trying to get a better understanding on when it is actually efficient to use serialization versus using delimiters+explode.

I didnt knew you can do that with an array too. I guess its nice for multidimensional ones. I just tested it, I guess it doesnt matter even if youre using what serialize uses as a delimiter on the array values. Darn, thats nice...
cecilia is offline  
Reply With Quote
Old 07-15-2009, 09:11 PM   #4 (permalink)
The Addict
 
Join Date: May 2009
Posts: 287
Thanks: 5
adamdecaf is on a distinguished road
Default

Quote:
Originally Posted by cecilia View Post
Isnt serialization used for converting an object into a string, allowing it to be stored on a database or passed by POST or GET?

At the moment, ive been trying to get a better understanding on when it is actually efficient to use serialization versus using delimiters+explode.

I didnt knew you can do that with an array too. I guess its nice for multidimensional ones. I just tested it, I guess it doesnt matter even if youre using what serialize uses as a delimiter on the array values. Darn, thats nice...
Thats sterilization.
__________________
My Site
adamdecaf is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't get PHP 5. to work? Newbie windows PHP guy DotNetTim Absolute Beginners 11 02-01-2013 11:02 AM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
Pure PHP template class. abiko Advanced PHP Programming 1 04-02-2008 05:45 PM
what are all the subjects in php? sarmenhb General 7 01-21-2008 05:41 PM


All times are GMT. The time now is 01:46 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design