# PHP.unserialize's strange behaviour

**URL:** <https://www.ruby-forum.com/t/php-unserializes-strange-behaviour/110958>\
**Category:** Ruby\
**Created:** [August 1, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/php-unserializes-strange-behaviour/110958 "2007-08-01T14:24:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [August 1, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/php-unserializes-strange-behaviour/110958/1 "2007-08-01T14:24:21Z")

</div>

I have some code that needs to obtain information from a web service in  
the form of an array of values to be plotted as a graph. The data I need  
come back in the form of a string, as seen at  
[http://users.ox.ac.uk/~lina0989/string.txt](http://users.ox.ac.uk/~lina0989/string.txt). So, the plan is to get at  
the data using this code:  
[http://www.aagh.net/files/ruby/php\_serialize.rb](http://www.aagh.net/files/ruby/php_serialize.rb)

If I run PHP.unserialize(string) then I get an array of nil values.  
However,  
PHP.serialize(PHP.unserialize(string)), or any equivalent, returns the  
same string I started off with. Has anyone got any idea as to what would  
cause this odd outcome?

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [August 4, 2007, 9:07pm UTC](https://www.ruby-forum.com/t/php-unserializes-strange-behaviour/110958/2 "2007-08-04T21:07:52Z")

</div>

- Milo T. (removed\_email\_address@domain.invalid) wrote:

> to what would cause this odd outcome?  
> How is it odd? You get the same thing unserializing in PHP.

Your string.txt: a:1920:{i:0;N;i:1;N;i:2;N; … ;i:1918;N;i:1919;N;}

Read as: Array, 1920 elements, comprised of: integer key 0, NULL value,  
integer key 1, NULL value, integer key 2, NULL value…

---

<div class="post-metadata">

**Author:** ![milo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/85e7bf/32.png) [@milo](https://www.ruby-forum.com/u/milo)\
**Post date:** [August 4, 2007, 9:33pm UTC](https://www.ruby-forum.com/t/php-unserializes-strange-behaviour/110958/3 "2007-08-04T21:33:14Z")

</div>

Thomas H. wrote:

> How is it odd?

Unfortunately for me it seemed odd because I cocked up and was causing a  
different string to be passed to my PHP and Ruby scripts without  
noticing the difference.  
Looking silly therefore serves me right, I suppose. 😊
