Req #63449 [Opn->Csd]: SplObjectStorage should work more like a real array()
| From: | ilutov@php.net | Date: | Fri, 22 Apr 2022 13:32:43 +0000 |
| Subject: | Req #63449 [Opn->Csd]: SplObjectStorage should work more like a real array() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241168@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63449&edit=1
ID: 63449
Updated by: ilutov@php.net
Reported by: dave at smartboy dot com
Summary: SplObjectStorage should work more like a real
array()
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: SPL related
Operating System: Linux
PHP Version: 5.4.8
-Assigned To:
+Assigned To: ilutov
Block user comment: N
Private report: N
New Comment:
SplObjectStorage (and ArrayAccess in general) only work for a single dimension. This is unlikely to
happen and thus I'm changing this feature request.
Previous Comments:
------------------------------------------------------------------------
[2012-11-06 21:31:43] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63449&edit=1