Professional Web Applications Themes

[PHP-DEV] superglobals inside of function declarations - PHP Development

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 cirvent 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 [url]www.netcollective.nl[/url] -- ...

  1. #1

    Default [PHP-DEV] superglobals inside of function declarations

    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 cirvent 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

    [url]www.netcollective.nl[/url]

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Filip de Waard Guest

  2. #2

    Default Re: [PHP-DEV] superglobals inside of function declarations

    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 cirvent 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
    >
    >[url]www.netcollective.nl[/url]
    >
    >--
    >PHP Internals - PHP Runtime Development Mailing List
    >To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Andi Gutmans Guest

  3. #3

    Default Re: [PHP-DEV] superglobals inside of function declarations

    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:
    > 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 cirvent 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
    > >
    > >[url]www.netcollective.nl[/url]
    > >
    > >--
    > >PHP Internals - PHP Runtime Development Mailing List
    > >To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Filip de Waard Guest

  4. #4

    Default Re: [PHP-DEV] superglobals inside of function declarations

    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 [url]http://derickrethans.nl/[/url]
    International PHP Magazine [url]http://php-mag.net/[/url]
    -------------------------------------------------------------------------

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Derick Rethans Guest

  5. #5

    Default Re: [PHP-DEV] superglobals inside of function declarations

    This one time, at band camp, Derick Rethans <derickphp.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

    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]

    Kevin Waterson Guest

Similar Threads

  1. how do you get a button to function inside movie clip ?
    By RadWall webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 22nd, 02:31 AM
  2. passing code inside function
    By Marcos Rebelo in forum PERL Beginners
    Replies: 4
    Last Post: December 9th, 01:14 PM
  3. Helper function inside template column
    By Chris in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: November 25th, 08:51 AM
  4. [PHP] include/require inside of function
    By Mike Ford in forum PHP Development
    Replies: 4
    Last Post: July 10th, 02:13 AM
  5. Delete array element from inside function
    By JS Bangs in forum PERL Miscellaneous
    Replies: 6
    Last Post: July 2nd, 05:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139