# superglobals inside of function declarations

- Thread: https://externals.io/message/5101
- Original archive: https://news-web.php.net/php.internals/5101
- Started by Filip de Waard on 2003-10-30T10:26:33+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #5101 — Filip de Waard — 2003-10-30T10:26:33+00:00

URL: https://externals.io/message/5101#5101

Hello,

I've been using PHP for quite a while now and i'm getting interested
it's internal beheaviour. I'm wondering why it isn't possible to use a
global variable inside of a function declaration. For example:

<?
function refresh($location = $_SERVER['PHP_SELF'])
{
	//refresh and load $location
}
//refreshes the page
refresh();
//redirects to another page
refresh("http://www.php.net/");
?>

Of course there are ways to circumvent this problem that have the same
result, but require more code. IMHO allowing globals inside of function
declarions will create interesting possibilities that could result in
more efficient code.

Regards,

Filip de Waard
Net Collective

www.netcollective.nl

---

## #5102 — Andi Gutmans — 2003-10-30T10:35:23+00:00

URL: https://externals.io/message/5101#5102 · In reply to: #5101

Hi,

In general you are only allowed to use scalars as default values. This 
won't change.

I suggest you do something like:

function refresh($location = NULL) {
    if ($location === NULL) {
        $location = $_SERVER['PHP_SELF'];
   }
}

At 11:26 AM 10/30/2003 +0100, Filip de Waard wrote:
>Hello,
>
>I've been using PHP for quite a while now and i'm getting interested
>it's internal beheaviour. I'm wondering why it isn't possible to use a
>global variable inside of a function declaration. For example:
>
><?
>function refresh($location = $_SERVER['PHP_SELF'])
>{
>         //refresh and load $location
>}
>//refreshes the page
>refresh();
>//redirects to another page
>refresh("http://www.php.net/");
>?>
>
>Of course there are ways to circumvent this problem that have the same
>result, but require more code. IMHO allowing globals inside of function
>declarions will create interesting possibilities that could result in
>more efficient code.
>
>Regards,
>
>Filip de Waard
>Net Collective
>
>www.netcollective.nl
