Edit report at http://bugs.php.net/bug.php?id=53835&edit=1
ID: 53835
User updated by: minisotm at gmail dot com
Reported by: minisotm at gmail dot com
Summary: shm_put_var and SplStack
Status: Open
Type: Bug
Package: Semaphore related
Operating System: *nix
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
HACK:
<?php
class HackStack extends \SplStack
{
private $_data;
public function __sleep()
{
$this->_data = array();
$this->rewind();
while ($this->valid()) {
$this->_data[] = $this->current();
$this->next();
}
return array('_data');
}
public function __wakeup()
{
foreach ($this->_data as $row) {
$this->push($row);
}
$this->_data = array ();
}
}
$SHM_KEY = ftok(__FILE__, chr( 4 ) );
$data = shm_attach($SHM_KEY, 102400, 0666);
$testData = array("hello","world","1","2","3");
$test = new HackStack();
$test->push($testData);
$test->push($testData);
echo "one: \n";
print_r($test);
shm_put_var($data, 1, $test);
echo "two: \n";
print_r(shm_get_var($data, 1));
shm_detach($data);
?>
RESULT:
one:
HackStack Object
(
[_data:HackStack:private] =>
[flags:SplDoublyLinkedList:private] => 6
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
[1] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
)
)
two:
HackStack Object
(
[flags:SplDoublyLinkedList:private] => 6
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
[1] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
)
)
Previous Comments:
------------------------------------------------------------------------
[2011-01-25 08:43:05] minisotm at gmail dot com
An object SplDoublyLinkedList () the same situation.
------------------------------------------------------------------------
[2011-01-25 08:32:53] minisotm at gmail dot com
Description:
------------
When trying to write an object through the function shm_put_var SplStack
it is
empty when invoking a shm_get_var.
Test script:
---------------
<?php
$SHM_KEY = ftok(__FILE__, chr( 4 ) );
$data = shm_attach($SHM_KEY, 102400, 0666);
$testData = array("hello","world","1","2","3");
$test = new SplStack();
$test->push($testData);
print_r($test);
shm_put_var($data, 1, $test);
print_r(shm_get_var($data, 1));
shm_detach($data);
Expected result:
----------------
one:
SplStack Object
(
[flags:SplDoublyLinkedList:private] => 6
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
)
)
two:
SplStack Object
(
[flags:SplDoublyLinkedList:private] => 6
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
)
)
Actual result:
--------------
one:
SplStack Object
(
[flags:SplDoublyLinkedList:private] => 6
[dllist:SplDoublyLinkedList:private] => Array
(
[0] => Array
(
[0] => hello
[1] => world
[2] => 1
[3] => 2
[4] => 3
)
)
)
two:
SplStack Object
(
[flags:SplDoublyLinkedList:private] => 6
[dllist:SplDoublyLinkedList:private] => Array
(
)
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53835&edit=1