php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58864 Reference sets not maintained.
Submitted: 2009-09-21 05:08 UTC Modified: 2016-11-18 20:52 UTC
From: stuart_hayton at uk dot ibm dot com Assigned:
Status: Wont fix Package: APC (PECL)
PHP Version: 5.2.6 OS: Ubuntu Linux 32bit
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: stuart_hayton at uk dot ibm dot com
New email:
PHP Version: OS:

 

 [2009-09-21 05:08 UTC] stuart_hayton at uk dot ibm dot com
Description:
------------
If I store an array containing references to a single value then I believe the reference set should be maintained when I fetch the value, behaving as though it had been serialized and deserialized. In the test case here only 1 member of the reference set is actually modified though the reference counts suggest that the set still exists.

Reproduce code:
---------------
<?php

$n = null;

// initialise an array with reference set
$s = 'some string';
$a[] =& $s; 
$a[] =& $s; 
$a[] =& $s; 
$s =& $n; // so the reference count is clear

debug_zval_dump($a);
var_dump(apc_store('a', $a));
$a = apc_fetch('a');

// modifiy it
$s =& $a[0];
$s = 'other string';
$s = & $n;

debug_zval_dump($a);

?>


Expected result:
----------------
array(3) refcount(2){
  [0]=>
  &string(11) "some string" refcount(3)
  [1]=>
  &string(11) "some string" refcount(3)
  [2]=>
  &string(11) "some string" refcount(3)
}
bool(true)
array(3) refcount(2){
  [0]=>
  &string(12) "other string" refcount(3)
  [1]=>
  &string(12) "other string" refcount(3)
  [2]=>
  &string(12) "other string" refcount(3)
}


Actual result:
--------------
array(3) refcount(2){
  [0]=>
  &string(11) "some string" refcount(3)
  [1]=>
  &string(11) "some string" refcount(3)
  [2]=>
  &string(11) "some string" refcount(3)
}
bool(true)
array(3) refcount(1){
  [0]=>
  &string(12) "other string" refcount(4)
  [1]=>
  &string(11) "some string" refcount(4)
  [2]=>
  &string(11) "some string" refcount(4)
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-22 06:33 UTC] gopalv82 at yahoo dot com
Ouch, I thought I got this right the last three times I fixed this.

A work-around this is to store the array as an object.

apc_store('a', (object)($a));

will do exactly what serialize/deserialize does.
 [2016-11-18 20:52 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-11-18 20:52 UTC] kalle@php.net
APC is no longer supported in favor of opcache that comes bundled with PHP, if you wish to use the user cache, then look at PECL/APCu.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jan 24 07:01:29 2025 UTC