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

From: Date: Mon, 20 Nov 2006 06:05:12 +0000
Subject: #39557 [Opn->Bgs]: Make functions accept superglobals as default value for its args
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-105193@lists.php.net to get a copy of this message
ID: 39557 Updated by: johannes@php.net 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: 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 this bug report at http://bugs.php.net/?id=39557&edit=1

« previous php.bugs (#105193) next »