Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002622 [Quercus] major always 04-23-08 05:34 05-15-08 13:52
Reporter perololo View Status public  
Assigned To nam
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 3.2.0 Product Version 3.1.5
  Product Build
Summary 0002622: serialize/unserialize do not handle references
Description 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)

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

Steps To Reproduce
Additional Information
Attached Files

- Relationships

- 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]
 

- Issue History
Date Modified Username Field Change
04-23-08 05:34 perololo New Issue
04-23-08 15:18 nam Note Added: 0003008
05-13-08 17:20 nam Status new => assigned
05-13-08 17:20 nam Assigned To  => nam
05-15-08 13:52 nam Status assigned => closed
05-15-08 13:52 nam Note Added: 0003074
05-15-08 13:52 nam Resolution open => fixed
05-15-08 13:52 nam Fixed in Version  => 3.2.0


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
31 total queries executed.
27 unique queries executed.
Powered by Mantis Bugtracker