|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #11472 function enhancements
Submitted: 2001-06-13 15:43 UTC Modified: 2001-06-20 17:20 UTC
From: webmaster at cd-lab dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.5 OS: Any
Private report: No CVE-ID: None
 [2001-06-13 15:43 UTC] webmaster at cd-lab dot com
Hi, I have a few ideas for enhancements to PHP's functions that would make them much more powerful.  

First, when using variable length argument lists (using func_get_arg, etc.) there should be a way to treat these as references.  As of now, it seems to me that only pass by value can be achieved with this mechanism.  A simple func_set_arg function would fill this gap nicely.

Second, macros would be a nice addition.

Third, and most important I believe, there needs to be a mechanism for inheriting scope in a function - rather than choosing between the extremes of global and local.  For instance, the following code demonstrates my point:

function a() {
   global $var;
   $var = 10;

function b() {
   $var = 5;
   print $var; # still prints 5 because a()'s $var is global
               # whereas b()'s var is local.  There is NO
               # way to reference b()'s var in a() as it
               # stands - the only way to do it would be to
               # make a() get passed a reference to $var

$var = 5;
print $var; # here, however, everything works fine because
            # the $var here is global

The behavior of a() here is, if not downright inconsistent, somewhat frustrating.  Now, consider if we had an inherit construct, which inherited the variable from the calling scope.  If a() then was defined as

function a() {
   inherit $a;
   $a = 10;

the behavior would be more consistent to what the writer of function b() intended.

With these additions, I think a lot more could be accomplished with functions.

Thanks for a great product,
Robby Walker


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-06-20 17:20 UTC]
hm, where to start ... 
- please have a single bug report for each issue,
  even in the feature request department 
- for requests as vague as the ones here you 
  should use instead

1) you would be deep in the function already
   when you call the func_get_arc() function,
   so parameter passing has already happend,
   and the decision to pass by value or by
   reference had already been taken

2) there is no big gain from having macros
   in an interpreted language IMHO

3) unrelated functions shouldn't see each
   others variables, no way

   inheriting variables from the calling 
   scope without knowing anything about
   the caller and with the caller not
   having control over what the called
   function is able to inherit is a very
   bad idea as it introduces lots of 

   nested functions as available in PASCAL 
   or optionally in gcc would be nice, but
   would break backwards compatiblity

   Classes might be what you are looking for ...

PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Jan 27 05:04:15 2023 UTC