php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #30935 compact fails for superglobals
Submitted: 2004-11-29 22:19 UTC Modified: 2005-01-18 04:06 UTC
Votes:5
Avg. Score:4.0 ± 0.6
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:2 (50.0%)
From: bugs-php-net at schirmeier dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.0.2 OS: Linux x86
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: bugs-php-net at schirmeier dot com
New email:
PHP Version: OS:

 

 [2004-11-29 22:19 UTC] bugs-php-net at schirmeier dot com
Description:
------------
compact() does not "see" superglobals like $_GET/$_POST/etc. when called within a function (documentation says: "Any strings that are not set will simply be skipped.").

Tested on PHP versions 4.3.2, 4.3.9 (both Apache module and cli), 5.0.0, 5.0.1 (cli), 5.0.2, php5.1-dev-cli.

Reproduce code:
---------------
<?php
function foo()
{
    var_dump(compact('_GET', '_POST', '_SESSION', '_ENV', '_COOKIE', '_SERVER'));
}

var_dump(compact('_GET', '_POST', '_SESSION', '_ENV', '_COOKIE', '_SERVER'));
echo "\n------------------------\n";
foo();
?>

Expected result:
----------------
A dump of an array with indexes '_GET', '_POST' etc. pointing to the contents of the respective superglobals, then a dashed line, then the same dump again.

Actual result:
--------------
The expected dump, the dashed line, and a:0:{}.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-29 22:22 UTC] bugs-php-net at schirmeier dot com
"Version:" corrected to latest "stable" version the bug was reproduced with.
 [2004-11-29 22:39 UTC] bugs-php-net at schirmeier dot com
Well, Keita Ito thankfully informed me about the "Warning:  Please note that variable variables cannot be used with PHP's Superglobal arrays within functions or class methods." on http://www.php.net/variables.variable -- which also seems to be valid for compact().

It'd be helpful if this could be included in the documentation for compact().

Or even better: Remove this weird behaviour for variable variables AND compact().
 [2004-11-29 23:17 UTC] derick@php.net
This is indeed a Documentation problem, marking as such.
 [2005-01-18 04:06 UTC] philip@php.net
This behavior has been documented. Thank you for the report, and locating the problem. Here's the diff:

http://cvs.php.net/diff.php/phpdoc/en/reference/array/functions/compact.xml?r1=1.7&r2=1.8

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 11:01:27 2024 UTC