php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32786 global on unset var messes up extract( , EXTR_SKIP)
Submitted: 2005-04-20 23:52 UTC Modified: 2005-04-21 00:31 UTC
From: mcrusch at svm dot vetmed dot wisc dot edu Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4CVS-2005-04-20 (stable) OS: Windows XP SP2
Private report: No CVE-ID: None
 [2005-04-20 23:52 UTC] mcrusch at svm dot vetmed dot wisc dot edu
Description:
------------
I called extract($array, EXTR_SKIP) in the global scope on an array and one of the variables did not extract, even thought it was not set.

I traced the problem to a function call in which there was a global statement involving the variable.  This seems to have created the variable in the global scope, but isset($var) (in the global scope) and isset($GLOBALS["var"]) both return false.  So, the variable is not set, but it will not extract.  

The only way to detect that it is in the symbol table is to do a print_r($GLOBALS), which allows you to visually see that it is there, but there is no way to programmatically detect it (other than capturing the output of print_r and parsing it--ugly!)

Problem also occurs on a SuSE 9.3 Linux box (Linux kernel v. 2.6.5-7.147-smp) running PHP 4.3.9

Reproduce code:
---------------
$arrayOfStuff = array("stuff" => "valueOfStuff");

echo isset($stuff).", ".isset($GLOBALS["stuff"]).", $stuff\n";

// Commenting out the globalStuff() call produces the 
// expected result

globalStuff();
extract($arrayOfStuff, EXTR_SKIP);

echo isset($stuff).", ".isset($GLOBALS["stuff"]).", $stuff\n";

function globalStuff() {
    global $stuff;
}

Expected result:
----------------
, , 
1, 1, valueOfStuff


Actual result:
--------------
, , 
, , 



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-20 23:54 UTC] mcrusch at svm dot vetmed dot wisc dot edu
SuSE version is 9.1, sorry.
 [2005-04-21 00:21 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 [2005-04-21 00:31 UTC] mcrusch at svm dot vetmed dot wisc dot edu
Can you give me the ID of the bug report that gives the exact same problem?  I have found many bug reports about extract(), but none that I have found describe a problem closely related to this one.

Thanks.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 15:01:33 2024 UTC