|  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
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
29 + 44 = ?
Subscribe to this entry?

 [2012-11-06 21:31 UTC] dave at smartboy dot com
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";

// 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";

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-07 03:10 UTC]
-Type: Bug +Type: Feature/Change Request
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 27 07:03:36 2021 UTC