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: http://nl2.php.net/manual/en/functions.arguments.php

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 parse error, which is correct, but not desirable I
think.

Parse error: parse error, unexpected T_VARIABLE in path\to\file.php on
line 1

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

Reply via email to