php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39557 Make functions accept superglobals as default value for its args
Submitted: 2006-11-19 23:13 UTC Modified: 2006-11-20 06:05 UTC
From: hermanscheele at gmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.0 OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hermanscheele at gmail dot com
New email:
PHP Version: OS:

 

 [2006-11-19 23:13 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-20 06:05 UTC] johannes@php.net
We're not going to change that.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 01:01:28 2024 UTC