Mantis - Quercus
Viewing Issue Advanced Details
2932 minor always 09-14-08 00:19 09-15-08 15:16
koreth  
ferg  
normal  
closed 3.2.1  
fixed  
none    
none 3.2.1  
0002932: Casting array to object drops numeric keys
<?php
print_r((object)array('a' => 'b'));
print_r((object)array(1 => 2));

Vanilla PHP prints

stdClass Object
(
    [a] => b
)
stdClass Object
(
    [1] => 2
)


Quercus prints

stdClass Object
(
    [a] => b
)
stdClass Object
(
)

Notes
(0003436)
koreth   
09-14-08 00:30   
Temporary workaround: Replace casts to "object" with calls to:

function to_object($value) {
  if (!is_array($value)) {
    return (object)$value;
  }
  $nval = (object)array();
  foreach ($value as $key => $val) {
    $nval->$key = $val;
  }
  return $nval;
}
(0003440)
ferg   
09-15-08 15:16   
php/03oe

Changed so Quercus converts the key to a string.

However, it looks like PHP is actually using an integer as the key, which seems odd since object keys are supposed to be strings.