php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53835 shm_put_var and SplStack
Submitted: 2011-01-25 08:32 UTC Modified: 2011-01-26 07:22 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: minisotm at gmail dot com Assigned: aharvey (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.5 OS: *nix
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: minisotm at gmail dot com
New email:
PHP Version: OS:

 

 [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
        (
        )

)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-25 08:43 UTC] minisotm at gmail dot com
An object SplDoublyLinkedList () the same situation.
 [2011-01-25 09:52 UTC] 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 20:47 UTC] johannes@php.net
-Status: Open +Status: To be documented
 [2011-01-25 20:47 UTC] 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-26 07:10 UTC] aharvey@php.net
-Status: To be documented +Status: Assigned -Type: Bug +Type: Documentation Problem -Package: Semaphore related +Package: Documentation problem -Assigned To: +Assigned To: aharvey
 [2011-01-26 07:22 UTC] aharvey@php.net
-Status: Assigned +Status: Closed
 [2011-01-26 07:22 UTC] aharvey@php.net
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.


 [2011-01-26 07:22 UTC] aharvey@php.net
Automatic comment from SVN on behalf of aharvey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=307746
Log: Fix doc bug #53835 (shm_put_var and SplStack).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Dec 14 22:00:01 2025 UTC