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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 08:01:34 2025 UTC