Edit report at https://bugs.php.net/bug.php?id=65135&edit=1

 ID:                 65135
 Updated by:         ni...@php.net
 Reported by:        sebast...@php.net
 Summary:            Support for non-scalar keys in foreach() does not
                     work with SplObjectStorage
-Status:             Assigned
+Status:             Wont fix
 Type:               Bug
 Package:            SPL related
 Operating System:   Irrelevant
 PHP Version:        5.5.0
 Assigned To:        nikic
 Block user comment: N
 Private report:     N

 New Comment:

Closing as Wfx as I don't see how we can reasonably change this.


Previous Comments:
------------------------------------------------------------------------
[2013-06-26 17:45:55] ni...@php.net

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-06-26 16:09:58] sebast...@php.net

Description:
------------
Quoting from https://wiki.php.net/rfc/foreach-non-scalar-keys

  // 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:
---------------
<?php
$o = new SplObjectStorage;
$o->attach(new DateTime, new StdClass);

foreach ($o as $key => $value) {
    var_dump($key);
    var_dump($value);
}

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

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


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65135&edit=1

Reply via email to