php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76040 URGENT (array)$object - Wrong attributes conversion
Submitted: 2018-03-01 19:57 UTC Modified: 2018-03-01 22:08 UTC
From: c dot rideron at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.0.28 OS: Ubuntu
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: c dot rideron at gmail dot com
New email:
PHP Version: OS:

 

 [2018-03-01 19:57 UTC] c dot rideron at gmail dot com
Description:
------------
Numeric keys in object convert as string keys to array.
And I can't access to this keys after conversion, because PHP automatic convert string numeric keys to integer.
In 7.1 too...

Test script:
---------------
$a=new stdClass();

$a->{1}=1;
$a->{2}=2;
$a->{3}=3;

$b=(array)$a;

var_dump([$b,1,@$b[1]]);

-----------------------------------------
  [0]=>
  array(3) {
    ["1"]=>
    int(1)
    ["2"]=>
    int(2)
    ["3"]=>
    int(3)
  }
  [1]=>
  int(1)
  [2]=>
  NULL



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-01 21:46 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-03-01 21:46 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Note that this behavior changed as of PHP 7.2.0. See
<https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts#backward_incompatible_changes>
for why the change has not been backported to older versions.
 [2018-03-01 22:08 UTC] c dot rideron at gmail dot com
I understood my fault.
It's next one good reason for upgrade to 7.2.
Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC