Mantis - Quercus
Viewing Issue Advanced Details
2622 major always 04-23-08 05:34 05-15-08 13:52
perololo  
nam  
normal  
closed 3.1.5  
fixed  
none    
none 3.2.0  
0002622: serialize/unserialize do not handle references
serialize/deserialize do not handle references at all.

- Instead of references, a copy of the referenced entity is stored to the serialised string.
- Deserialising a Zend-PHP based string with references failes, too.

====================================================================
See the following example:
====================================================================
<?php
header("Content-type: text/plain");

    echo "Testing references:\n".
         "===================\n\n";

    $val1 = "original value";
    $val2 = array("copied value with a reference inside");
    $val2["reference"] =& $val1;
    $val2["copy"] = $val1;

    $stack = array();
    $stack["ref to val1"] =& $val1;
    $stack[] = $val2;
    
    $val1 = "new value";
    
    $val2Copy =& $stack[1];
    $val2Copy["aVal"] = "aVal";
    
    echo "stack content with references is: \n";
    var_dump($stack);

    echo "\nserialized: \n";
    echo serialize($stack) . "\n";
    
    // unserialize the same array but created with original Zend PHP 5.0
    echo "\nunserializin from original PHP: \n";
    $unserializedValue = unserialize('a:3:{s:11:"ref to val1";s:9:"new value";i:0;a:3:{i:0;s:36:"copied value with a reference inside";s:9:"reference";R:2;s:4:"copy";s:14:"original value";}i:1;a:1:{s:4:"aVal";s:4:"aVal";}}');
    var_dump($unserializedValue);
    
    
    echo "\n\nQuercus version: " . $_SERVER["SERVER_SOFTWARE"];
?>
====================================================================




====================================================================
output with Zend PHP 5.2:
====================================================================
Testing references:
===================

stack content with references is:
array(3) {
  ["ref to val1"]=>
  &string(9) "new value"
  [0]=>
  array(3) {
    [0]=>
    string(36) "copied value with a reference inside"
    ["reference"]=>
    &string(9) "new value"
    ["copy"]=>
    string(14) "original value"
  }
  [1]=>
  &array(1) {
    ["aVal"]=>
    string(4) "aVal"
  }
}

serialized:
a:3:{s:11:"ref to val1";s:9:"new value";i:0;a:3:{i:0;s:36:"copied value with a reference inside";s:9:"reference";R:2;s:4:"copy";s:14:"original value";}i:1;a:1:{s:4:"aVal";s:4:"aVal";}}

unserializin from original PHP:
array(3) {
  ["ref to val1"]=>
  &string(9) "new value"
  [0]=>
  array(3) {
    [0]=>
    string(36) "copied value with a reference inside"
    ["reference"]=>
    &string(9) "new value"
    ["copy"]=>
    string(14) "original value"
  }
  [1]=>
  array(1) {
    ["aVal"]=>
    string(4) "aVal"
  }
}


Quercus version: Apache
====================================================================



====================================================================
output with Quercus 3.1.5:
(although I have downloaded quercus-3.1.5.war, quercus reports
version 3.1.2)
====================================================================
Testing references:
===================

stack content with references is:
array(3) {
  ["ref to val1"]=>
  &string(9) "new value"
  [0]=>
  array(3) {
    [0]=>
    string(36) "copied value with a reference inside"
    ["reference"]=>
    &string(9) "new value"
    ["copy"]=>
    string(14) "original value"
  }
  [1]=>
  &array(1) {
    ["aVal"]=>
    string(4) "aVal"
  }
}

serialized:
a:3:{s:11:"ref to val1";s:9:"new value";i:0;a:3:{i:0;s:36:"copied value with a reference inside";s:9:"reference";s:9:"new value";s:4:"copy";s:14:"original value";}i:1;a:1:{s:4:"aVal";s:4:"aVal";}}

unserializin from original PHP:
bool(false)


Quercus version: Apache PHP Quercus(Open Source 3.1.2)

====================================================================


Notes
(0003008)
nam   
04-23-08 15:18   
Simplified test case
====================
$a = "hello";

$b = array();
$b[0] = &$a;
$b[1] = &$a;

$s = serialize($b);
var_dump($s);
var_dump(unserialize($s));

Expected output:
================
string(30) "a:2:{i:0;s:5:"hello";i:1;R:2;}"
array(2) {
  [0]=>
  &string(5) "hello"
  [1]=>
  &string(5) "hello"
}
(0003074)
nam   
05-15-08 13:52   
php/121[g-q]
php/122[g-r]