php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55135 Array keys are no longer type casted in unset()
Submitted: 2011-07-05 09:23 UTC Modified: 2011-07-07 04:39 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: damien at commerceguys dot com Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5.4SVN-2011-07-05 (SVN) OS: Linux
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: damien at commerceguys dot com
New email:
PHP Version: OS:

 

 [2011-07-05 09:23 UTC] damien at commerceguys dot com
Description:
------------
An array key passed to unset() from a variable doesn't seem to be typecasted anymore.


Test script:
---------------
This doesn't work anymore in PHP 5.4:

<?php
// This fails.
$array = array(1 => 2);
$a = "1";
unset($array[$a]);
print_r($array);

// Those works.
$array = array(1 => 2);
$a = 1;
unset($array[$a]);
print_r($array);

$array = array(1 => 2);
unset($array[1]);
print_r($array);

$array = array(1 => 2);
$a = 1;
unset($array["1"]);
print_r($array);
?>

Expected result:
----------------
Array
(
)
Array
(
)
Array
(
)
Array
(
)


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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-05 14:58 UTC] johannes@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: dmitry
 [2011-07-06 08:04 UTC] dmitry@php.net
Automatic comment from SVN on behalf of dmitry
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=313005
Log: Fixed bug #55135 (Array keys are no longer type casted in unset())
 [2011-07-06 08:04 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 [2011-07-06 08:04 UTC] dmitry@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2011-07-07 04:39 UTC] damien at commerceguys dot com
Confirmed that this issue is fixed. Thanks. The bulk of the Drupal 8 test suite now passes on PHP 5.4 ;)
 [2012-04-18 09:49 UTC] laruence@php.net
Automatic comment on behalf of dmitry
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3931078e7fd46c544887262c1edeb8d53294e52f
Log: Fixed bug #55135 (Array keys are no longer type casted in unset())
 [2012-07-24 23:41 UTC] rasmus@php.net
Automatic comment on behalf of dmitry
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3931078e7fd46c544887262c1edeb8d53294e52f
Log: Fixed bug #55135 (Array keys are no longer type casted in unset())
 [2013-11-17 09:37 UTC] laruence@php.net
Automatic comment on behalf of dmitry
Revision: http://git.php.net/?p=php-src.git;a=commit;h=3931078e7fd46c544887262c1edeb8d53294e52f
Log: Fixed bug #55135 (Array keys are no longer type casted in unset())
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 15:01:30 2025 UTC