Professional Web Applications Themes

#39557 [NEW]: Make functions accept superglobals as default value for its args - PHP Bugs

From: hermanscheele at gmail dot com Operating system: * PHP version: 5.2.0 PHP Bug Type: Feature/Change Request Bug description: Make functions accept superglobals as default value for its args Description: ------------ This is really a request to make an exception to the following limitation: "The default value must be a constant expression, not (for example) a variable, a class member or a function call." Quoted from: [url]http://nl2.php.net/manual/en/functions.arguments.php[/url] It's my guess that this has to do with the vars scope getting messy, but I think superglobals would qualify for an exception to this. Constants are already accepted. Reproduce code: --------------- function ...

  1. #1

    Default #39557 [NEW]: Make functions accept superglobals as default value for its args

    From: hermanscheele at gmail dot com
    Operating system: *
    PHP version: 5.2.0
    PHP Bug Type: Feature/Change Request
    Bug description: Make functions accept superglobals as default value for its args

    Description:
    ------------
    This is really a request to make an exception to the following
    limitation:

    "The default value must be a constant expression, not (for example) a
    variable, a class member or a function call."

    Quoted from: [url]http://nl2.php.net/manual/en/functions.arguments.php[/url]

    It's my guess that this has to do with the vars scope getting messy, but I
    think superglobals would qualify for an exception to this.

    Constants are already accepted.

    Reproduce code:
    ---------------
    function foo($bar=$_SERVER['REMOTE_ADDR'])
    {
    echo('Given IP is: '.$bar.'<br />');
    }
    foo('192.168.1.1');
    foo();

    Expected result:
    ----------------
    I would expect PHP to echo the submitted string the first function-call.
    And echo the clients IP the second call.

    Actual result:
    --------------
    I get the following p error, which is correct, but not desirable I
    think.

    P error: p error, unexpected T_VARIABLE in path\to\file.php on
    line 1

    --
    Edit bug report at [url]http://bugs.php.net/?id=39557&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39557&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39557&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39557&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39557&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39557&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39557&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39557&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39557&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39557&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39557&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39557&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39557&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39557&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39557&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39557&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39557&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39557&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39557&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39557&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39557&r=mysqlcfg[/url]
    hermanscheele at gmail dot com Guest

  2. #2

    Default #39557 [Opn->Bgs]: Make functions accept superglobals as default value for its args

    ID: 39557
    Updated by: [email]johannesphp.net[/email]
    Reported By: hermanscheele at gmail dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Feature/Change Request
    Operating System: *
    PHP Version: 5.2.0
    New Comment:

    We're not going to change that.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-19 23:13:26] hermanscheele at gmail dot com

    Description:
    ------------
    This is really a request to make an exception to the following
    limitation:

    "The default value must be a constant expression, not (for example) a
    variable, a class member or a function call."

    Quoted from: [url]http://nl2.php.net/manual/en/functions.arguments.php[/url]

    It's my guess that this has to do with the vars scope getting messy,
    but I think superglobals would qualify for an exception to this.

    Constants are already accepted.

    Reproduce code:
    ---------------
    function foo($bar=$_SERVER['REMOTE_ADDR'])
    {
    echo('Given IP is: '.$bar.'<br />');
    }
    foo('192.168.1.1');
    foo();

    Expected result:
    ----------------
    I would expect PHP to echo the submitted string the first
    function-call. And echo the clients IP the second call.

    Actual result:
    --------------
    I get the following p error, which is correct, but not desirable I
    think.

    P error: p error, unexpected T_VARIABLE in path\to\file.php on
    line 1


    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39557&edit=1[/url]
    johannes@php.net Guest

Similar Threads

  1. #40311 [NEW]: Superglobals appearing as empty within functions
    By tretton at gmail dot com in forum PHP Bugs
    Replies: 2
    Last Post: February 2nd, 09:24 AM
  2. Replies: 0
    Last Post: September 18th, 10:04 AM
  3. Replies: 0
    Last Post: September 11th, 02:13 PM
  4. Replies: 0
    Last Post: September 11th, 08:24 AM
  5. Replies: 0
    Last Post: September 11th, 08:21 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