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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
22 + 32 = ?
Subscribe to this entry?

 
 [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: Thu Oct 31 23:01:28 2024 UTC