superglobals inside of function declarations

php.internals

Filip de Waard

22 years ago
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

Andi Gutmans

22 years ago
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:

Filip de Waard

22 years ago
Andy, I know the current possibilities and limitations, but i'm wondering why superglobals can't be used in function declarations. Is there a particular reason for this? Regards, Filip de Waard On Thu, 2003-10-30 at 11:35, Andi Gutmans wrote:

Derick Rethans

22 years ago
On Thu, 30 Oct 2003, Filip de Waard wrote:
> Andy, > > I know the current possibilities and limitations, but i'm wondering why > superglobals can't be used in function declarations. Is there a > particular reason for this?
Because PHP just only supports scalar constants there. Derick
-- "Interpreting what the GPL actually means is a job best left to those that read the future by examining animal entrails." ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ International PHP Magazine http://php-mag.net/ -------------------------------------------------------------------------

Kevin Waterson

22 years ago
This one time, at band camp, Derick Rethans <derick@php.net> wrote:
> On Thu, 30 Oct 2003, Filip de Waard wrote: > > > Andy, > > > > I know the current possibilities and limitations, but i'm wondering why > > superglobals can't be used in function declarations. Is there a > > particular reason for this? > > Because PHP just only supports scalar constants there.
why would you ever _want_ to? The purpose of a super global is that it is available in all scopes. Kevin
-- ______ (_____ \ _____) ) ____ ____ ____ ____ | ____/ / _ ) / _ | / ___) / _ ) | | ( (/ / ( ( | |( (___ ( (/ / |_| \____) \_||_| \____) \____) Kevin Waterson Port Macquarie, Australia