From:             sebastian
Operating system: Irrelevant
PHP version:      5.5.0
Package:          SPL related
Bug Type:         Bug
Bug description:Support for non-scalar keys in foreach() does not work with 
SplObjectStorage

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 bug report at https://bugs.php.net/bug.php?id=65135&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=65135&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=65135&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=65135&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=65135&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=65135&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=65135&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=65135&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=65135&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=65135&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=65135&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=65135&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=65135&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=65135&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65135&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=65135&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=65135&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=65135&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65135&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=65135&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=65135&r=mysqlcfg

Reply via email to