php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63449 SplObjectStorage should work more like a real array()
Submitted: 2012-11-06 21:31 UTC Modified: 2012-11-07 03:10 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: dave at smartboy dot com Assigned:
Status: Open Package: SPL related
PHP Version: 5.4.8 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dave at smartboy dot com
New email:
PHP Version: OS:

 

 [2012-11-06 21:31 UTC] dave at smartboy dot com
Description:
------------
Attempting to use instances of class SplObjectStorage as an array results in 
exceptions and generally does not work as expected.

Test script:
---------------
$s = new SplObjectStorage;
$o = new stdClass;
$s[$o]["key"] = "value";
var_export($s[$o]);

// Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Object not found'

Expected result:
----------------
The above sample code should create an array for the object key inside 
SplObjectStorage, and display:

array (
  'key' => 'value',
)

Compare the above code with: 

$s = array();
$o = "someKey";
$s[$o]["key"] = "value";
var_export($s[$o]);

which works as expected and displays

array (
  'key' => 'value',
)


Actual result:
--------------
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Object 
not found' in Command line code:1
Stack trace:
#0 Command line code(1): SplObjectStorage->offsetGet(Object(stdClass))
#1 {main}
  thrown in Command line code on line 1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-07 03:10 UTC] laruence@php.net
-Type: Bug +Type: Feature/Change Request
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 04:01:24 2020 UTC