php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75908 unset do not work
Submitted: 2018-02-02 14:05 UTC Modified: 2018-02-02 14:28 UTC
From: novoyura2 at gmail dot com Assigned: peehaa (profile)
Status: Closed Package: Arrays related
PHP Version: 5.6.33 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: novoyura2 at gmail dot com
New email:
PHP Version: OS:

 

 [2018-02-02 14:05 UTC] novoyura2 at gmail dot com
Description:
------------
Cant get element by key after transform object to array

Test script:
---------------
$a = [0 => 1, 1=>3, 2=> 6];
print_r($a);
$o  = new stdClass();
foreach($a as $key => $value){
	$o->$key = $value;
}

$a = (array)$o;
print_r($a);
foreach ($a as $key => $id) {
                unset($a[$key]);
	
        }

print_r($a);

Expected result:
----------------
Array ( [0] => 1 [1] => 3 [2] => 6 ) Array ( [0] => 1 [1] => 3 [2] => 6 ) Array()

Actual result:
--------------
Array ( [0] => 1 [1] => 3 [2] => 6 ) Array ( [0] => 1 [1] => 3 [2] => 6 ) Array ( [0] => 1 [1] => 3 [2] => 6 )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-02 14:19 UTC] peehaa@php.net
This has already been fixed in 7.2.0.

https://3v4l.org/eDiXa

Might also need to be fixed in 7.1 as that is still supported?
 [2018-02-02 14:28 UTC] peehaa@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: peehaa
 [2018-02-02 14:28 UTC] peehaa@php.net
This specifically targeted 7.2:

https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 15 14:01:36 2024 UTC