#25708 [Opn->WFx]: extract($GLOBALS, EXTR_REFS); can corrupt the $GLOBALS array.

From: Date: Wed, 01 Oct 2003 00:57:16 +0000
Subject: #25708 [Opn->WFx]: extract($GLOBALS, EXTR_REFS); can corrupt the $GLOBALS array.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-48358@lists.php.net to get a copy of this message
ID: 25708 Updated by: sniper@php.net Reported By: cdragon at draconic dot com -Status: Open +Status: Wont fix Bug Type: Variables related Operating System: Windows 2000 Server PHP Version: 4CVS-2003-09-30 (stable) New Comment: In short: Don't do this. Longer version: GLOBALS is special variable, using extract() on it is a) pointless, b) stupid, c) useless. GLOBALS references itself in it, when you try to extract it's contents as references, you'll end up with circular references which of course will cause a crash. Previous Comments: ------------------------------------------------------------------------ [2003-09-30 18:23:05] cdragon at draconic dot com Description: ------------ Using extract($GLOBALS, EXTR_REFS); can cause the left hand side of two globals set "by-value" equal to one-another to become corrupted in the $GLOBALS array. Hard to explain in English, but easier to see in the code below. Reproduce code: --------------- $sortColumn = "Affinity"; // Using "$lastSortColumn = substr($sortColumn, 0);" fixes the bug $lastSortColumn = $sortColumn; print "sort=" . $GLOBALS['sortColumn'] . " lastsort=" . $GLOBALS['lastSortColumn'] . "<p>"; extractGlobs(); print "sort=" . $GLOBALS['sortColumn'] . " lastsort=" . $GLOBALS['lastSortColumn'] . "<p>"; function extractGlobs() { // Commenting out the line below fixes the bug. So does not using the EXTR_REFS flag. extract($GLOBALS, EXTR_REFS); } Expected result: ---------------- sort=Affinity lastsort=Affinity sort=Affinity lastsort=Affinity Actual result: -------------- sort=Affinity lastsort=Affinity sort=Affinity lastsort= or, randomly, you get an access violation instead: PHP has encountered an Access Violation at 02CFF32F (the 02CFF32F is variable) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25708&edit=1

« previous php.bugs (#48358) next »