|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-01-25 08:32 UTC] 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
(
)
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 14 22:00:01 2025 UTC |
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 ) ) )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.)