When php returns a serialized string, does it only rely on the input value or do outside sources (the environment) play any part at all?
The reason why I am asking this is, I am seeing some arrays that I believe to be identical get serialized slightly different per session.
I wrote this which demonstrates that they are always the same within the same session:
<?php
$arr = array("something here", "foo" => "something else", "bar" => array( "nested" => "temp", 5232), 3434);
$s = serialize($arr);
for( $i = 1; $i <= 100; $i++ )
{
$s2 = serialize($arr);
if( $s2 != $s )
{
echo "They are not always the same";
break;
}
if($i == 100)
{
echo "They are always the same";
}
}
?>
So either there is something causing them to be created differently on different connections, or my arrays that appear to be identical are somehow not.
Serialized strings are human readable. They can be broken down as follows:
The first letter is the datatype, array, the number is the length/size of the object. So next up you have an integer of 0 and then a string 14 characters in length. So now you can read the format can you see any differences?
When I run your code on codepad it works as expected. So perhaps there is more at play here like in your actual code you are trying to serialize an object.