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: 2022-04-22 13:32 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: ilutov (profile)
Status: Closed Package: SPL related
PHP Version: 5.4.8 OS: Linux
Private report: No CVE-ID: None
 [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
 [2022-04-22 13:32 UTC] ilutov@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ilutov
 [2022-04-22 13:32 UTC] ilutov@php.net
SplObjectStorage (and ArrayAccess in general) only work for a single dimension. This is unlikely to happen and thus I'm changing this feature request.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC