|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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)
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 12:00:01 2025 UTC |
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.