Doc #53835 [Asn->Csd]: shm_put_var and SplStack
| From: | aharvey@php.net | Date: | Wed, 26 Jan 2011 06:22:00 +0000 |
| Subject: | Doc #53835 [Asn->Csd]: shm_put_var and SplStack | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5862@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53835&edit=1
ID: 53835
Updated by: aharvey@php.net
Reported by: minisotm at gmail dot com
Summary: shm_put_var and SplStack
-Status: Assigned
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
Operating System: *nix
PHP Version: 5.3.5
Assigned To: aharvey
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2011-01-25 20:47:47] johannes@php.net
The issue here is that the data is serialized. The docs on
shm_put_var()currently state
All variable-types except resources are supported.
Which is not correct as serialisation of objects from interal classes
(PDO, DOM, SPL, ...) is often not possible for various reasons
(representing C structures etc.)
------------------------------------------------------------------------
[2011-01-25 09:52:31] minisotm at gmail dot com
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
)
)
)
------------------------------------------------------------------------
[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