php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70251 extract() turns array array elements to references
Submitted: 2015-08-12 16:58 UTC Modified: 2015-08-12 17:06 UTC
From: bugs dot php dot net at ss dot st dot tc Assigned:
Status: Duplicate Package: Arrays related
PHP Version: 7.0Git-2015-08-12 (Git) OS: Gentoo Linux
Private report: No CVE-ID: None
 [2015-08-12 16:58 UTC] bugs dot php dot net at ss dot st dot tc
Description:
------------
extract() turns array elements back to references after they were once referenced and despite the reference was removed.
Tested on PHP 5.6.12 (works as expected), 7.0b3 (buggy) and git rev 2366a070c8 (buggy).


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

$array = ['key' => 'value'];

// create a reference to an element of the array
$ref = & $array['key'];

// make sure array element is a reference
var_dump($array);

// remove the $ref reference
unset($ref);

// make sure array elements are no longer references
var_dump($array);

extract($array);

// make sure array elements are still no references
var_dump($array);


Expected result:
----------------
array(1) {
  ["key"]=>
  &string(5) "value"
}
array(1) {
  ["key"]=>
  string(5) "value"
}
array(1) {
  ["key"]=>
  string(5) "value"
}


Actual result:
--------------
array(1) {
  ["key"]=>
  &string(5) "value"
}
array(1) {
  ["key"]=>
  string(5) "value"
}
array(1) {
  ["key"]=>
  &string(5) "value"   <=== reference again
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-12 17:01 UTC] bugs dot php dot net at ss dot st dot tc
-Status: Open +Status: Closed
 [2015-08-12 17:01 UTC] bugs dot php dot net at ss dot st dot tc
Duplicate of #70250 (accidentally hit "submit" twice).
 [2015-08-12 17:06 UTC] nikic@php.net
-Status: Closed +Status: Duplicate
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jan 17 23:01:24 2019 UTC