4

Uses of serialize() in php.its advantages and dis advantages

sandeep
  • 2,862
  • 9
  • 44
  • 54

6 Answers6

12

Advantages:

Turns objects into a string

Disadvantages:

Turns objects into a string

fire
  • 21,383
  • 17
  • 79
  • 114
  • 2
    @Bolt I disagree. This is not an answer, It just mocks the OP's original poor question. I don't see why it should be upvoted when the OP gets close- and downvoted. – Gordon Jan 17 '11 at 09:57
  • @Gordon Well seems the moral is: A bad question deserves a bad answer:) And this thread deserves to be closed, both OP's question and the answers here were below SO standard – Sondre Jan 17 '11 at 10:14
  • 1
    @Sondre no, it doesn't. It deserves no answer at all or a comment at worst. I understand the urge to provide an snide remark like this, but providing it as an answer is repwhoring. I agree that the Q should be closed (which is why I closevoted) – Gordon Jan 17 '11 at 10:18
  • 2
    @gordon Ye I totally agree with you, was merly pointing out that people seems to enjoy voting up answers making fun of a poorly asked OP. People just see it as a safe and easy way to get some rep without really contributing at all – Sondre Jan 17 '11 at 10:26
  • @Gordon: I didn't upvote. I happen to also be the first close voter. – BoltClock Jan 17 '11 at 10:46
6

Disadvantages

Advantages

PHP provides magic methods allowing you to handle this disadvantage

Gordon
  • 312,688
  • 75
  • 539
  • 559
Mark Baker
  • 209,507
  • 32
  • 346
  • 385
1

I dont see any disadvantage of serialization.

Advantage is that you can serialize objects and arrays and save them (for example in database). Later, you can get objects back (unserialize) in the exactly same state, in which they were saved.

Andreyco
  • 22,476
  • 5
  • 61
  • 65
1

http://us2.php.net/manual/en/function.serialize.php

Chris Tonkinson
  • 13,823
  • 14
  • 58
  • 90
1

It turns the object or array passed to it as the first (and only) argument to a string. This function is useful for storing objects in a database or file, for example. To turn the string back into an object or array, use unserialize(). Also look at the documentation of the function at: http://us2.php.net/manual/en/function.serialize.php

Amit Eyal
  • 459
  • 3
  • 11
-1

Only disadvantage is with utf8 encoding!

Edmhs
  • 3,645
  • 27
  • 39
  • 1
    Can you explain? I've never had any problems with UTF-8 values and serialization... only with faulty storage of serialized objects that contain UTF-8 values – Mark Baker Jan 17 '11 at 09:58
  • but i did had, so thats why i used json – Edmhs Jan 17 '11 at 10:07
  • http://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize -JSON converts UTF-8 characters to unicode escape sequences. serialize() does not. – Edmhs Jan 17 '11 at 10:10
  • 1
    @Eddsstudio - what was your problem? – Mark Baker Jan 17 '11 at 10:12
  • I needed to cache some arrays into files, and had some problems with symbols in latvian. – Edmhs Jan 17 '11 at 10:29
  • Shouldn't be a problem if all you're doing is reading and writing those files... just don't edit them manually unless it's with an editor that will treat them as UTF-8. – Mark Baker Jan 17 '11 at 11:23