[PHP-BUG] Bug #71208 [NEW]: Array/Object cast looses numeric property/element accessibility

[email protected] ("[email protected]")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             ajf
Operating system: OS X 10.11 El Capitan
PHP version:      7.0.1
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:Array/Object cast looses numeric property/element accessibility

Description:
------------
If an array is casted to an object, its integer keys become inaccessible
integer(!) key properties. They should be normal string key properties
instead.

Test script:
---------------
<?php

$arr = [1, 2, 4];
$obj = (object)$arr;

var_dump($obj);
var_dump($obj->{1}, $obj->{2}, $obj->{3});
var_dump($obj->{'1'}, $obj->{'2'}, $obj->{'3'});

?>

Expected result:
----------------
object(stdClass)#1 (3) {
  ["0"]=>
  int(1)
  ["1"]=>
  int(2)
  ["2"]=>
  int(4)
}
int(1)
int(2)
int(4)
int(1)
int(2)
int(4)

Actual result:
--------------
object(stdClass)#1 (3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
}

Notice: Undefined property: stdClass::$1 in - on line 7

Notice: Undefined property: stdClass::$2 in - on line 7

Notice: Undefined property: stdClass::$3 in - on line 7

NULL
NULL
NULL

Notice: Undefined property: stdClass::$1 in - on line 8

Notice: Undefined property: stdClass::$2 in - on line 8

Notice: Undefined property: stdClass::$3 in - on line 8

NULL
NULL
NULL

-- 
Edit bug report at https://bugs.php.net/bug.php?id=71208&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=71208&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=71208&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=71208&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=71208&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=71208&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=71208&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=71208&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=71208&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=71208&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=71208&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=71208&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=71208&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=71208&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71208&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=71208&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=71208&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=71208&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71208&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=71208&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=71208&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.