# #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. ## #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. ## #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

#### Posting Permissions

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