|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2015-11-13 10:57 UTC] php at maisqi dot com
 Description: ------------ extract() sets the values of variables that reference variables, instead of changing the variables that they point to. For example, say $ref is a reference to $var; if extract() has a "ref" var to inject in the current scope, it changes $ref and does nothing to $var -- it breaks the reference. NOTE: My tests was on PHP 7RC7 64 bits on Windows, though this probably isn't relevant. Test script: --------------- <?php $var = 'original value'; $ref =& $var; $hash = ['var' => 'new value']; extract($hash); echo 'ref: ', $ref, ' var: ', $var; Expected result: ---------------- ref: new value var: new value (This is what happens on PHP 5.6/64 bits) Actual result: -------------- ref: original value var: new value PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 03:00:01 2025 UTC | 
@laruence: My intuition would say that extract() without EXTR_REFS should behave the same was as manually doing the assignments, i.e.: extract(['a' => 'b', 'c' => 'd']); // should be the same as writing $a = 'b'; $c = 'd'; So in this case the equivalent code without extract() would be: $var = 'original value'; $ref =& $var; $var = 'new value'; In which case the result that PHP 5.6 provides is correct. If EXTR_REFS is specified then all assignments should happen with =&, which breaks references. In this case the current behavior matches the previous one already.