|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65135 Support for non-scalar keys in foreach() does not work with SplObjectStorage
Submitted: 2013-06-26 16:09 UTC Modified: 2013-07-06 16:35 UTC
From: Assigned: nikic (profile)
Status: Wont fix Package: SPL related
PHP Version: 5.5.0 OS: Irrelevant
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.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2013-06-26 16:09 UTC]
Quoting from

  // NOT possible
  foreach ($objectStore as $key => $value) {
    // ...
  // Instead you have to use
  foreach ($objectStore as $key) {
    $value = $objectStore[$key];
    // ...

This suggests that it would work after the proposed changes. However, in PHP 5.5 (for which the RFC was accepted) this still does not work.

Test script:
$o = new SplObjectStorage;
$o->attach(new DateTime, new StdClass);

foreach ($o as $key => $value) {

Expected result:
class DateTime#2 (3) {
  public $date =>
  string(19) "2013-06-26 18:04:30"
  public $timezone_type =>
  public $timezone =>
  string(13) "Europe/Berlin"
class stdClass#3 (0) {

Actual result:
class DateTime#2 (3) {
  public $date =>
  string(19) "2013-06-26 18:03:24"
  public $timezone_type =>
  public $timezone =>
  string(13) "Europe/Berlin"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-26 16:11 UTC]
-Assigned To: +Assigned To: nikic
 [2013-06-26 17:45 UTC]
The RFC only adds the ability to have non-scalar keys. It does not change the behavior of any of our existing iterators.

I don't think we can change the SplObjectStorage behavior as it would constitute a BC break (all current loops would break.)
 [2013-07-06 16:35 UTC]
-Status: Assigned +Status: Wont fix
 [2013-07-06 16:35 UTC]
Closing as Wfx as I don't see how we can reasonably change this.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Dec 07 04:01:28 2023 UTC