0
   

Serialize in php

 
 
Reply Wed 20 Jan, 2010 02:49 am
what is the need of serialization in php?

can anyone explain ..?

Thanks in advance
By
Ars
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 2,799 • Replies: 5
No top replies

 
gungasnake
 
  1  
Reply Wed 20 Jan, 2010 05:09 am
@Aravindh,
Php to me at least looks more like C or at most C with classes than it does like C++ so that in a way it favors older people. I've never needed classes for anything I've done with Php so the subject hasn't come up.

In C or C++ normally to to do old-fashioned writing and reading of objects or structures of a fixed size, I'd just as soon use structures and fread/fwrite statements, to me at least that's a little bit easier to read.

The problem arises when an object contains pointers to allocated memory and objects can vary in size. C++ IO does not handle that for you; what you'd do normally would be to define << and >> operators which pick up sizes from a header of some sort and then read/write the rest of the object.

I'd assume the main point of any sort of a decent serialization system would be to handle that sort of thing without the need for such metadata in objects.
Robert Gentel
 
  2  
Reply Wed 20 Jan, 2010 11:49 pm
@Aravindh,
It's basically like delimiting, or a way to format structured data as a string. So you can do things like take an array and serialize it and store it with the structure as a single value. When you need it back as an array you can unserialize it.

Here is an article with more info:

http://www.devshed.com/c/a/PHP/The-Basics-of-Serializing-Objects-in-PHP/
0 Replies
 
hariharan
 
  1  
Reply Mon 12 Apr, 2010 01:03 am
@gungasnake,
may be
monbasala
 
  1  
Reply Wed 27 Oct, 2010 10:35 am
@hariharan,
You can format an array data to string and insert your database,And unserialize it to an array.
nikkoncolmel
 
  0  
Reply Thu 27 Sep, 2012 03:06 am
@monbasala,
where serialize() comes in. You can pass an array to the function, and it will return a string that is essentially the array flattened and mashed down. You can then unserialize() it to obtain the full array once again.

<?php
$the_array = array( "Lorem", "Ipsum", "Dolor" );
$serialized = serialize($the_array);
print $serialized;
?>
0 Replies
 
 

Related Topics

Webdevelopment and hosting - Question by harisit2005
Showing an Ico File - Discussion by Brandon9000
how to earn money in internet - Discussion by rizwanaraj
The version 10 bug. Worse then Y2K! - Discussion by Nick Ashley
CSS Border style colors - Question by meesa
There is no Wisdom in Crowds - Discussion by ebrown p
THANK YOU CRAVEN AND NICK!!! - Discussion by dagmaraka
I'm the developer - Discussion by Nick Ashley
 
  1. Forums
  2. » Serialize in php
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/24/2024 at 10:47:02