Bug #11472 Updated: function enhancements
| From: | hholzgra@php.net | Date: | Wed, 20 Jun 2001 21:20:57 +0000 |
| Subject: | Bug #11472 Updated: function enhancements | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-57470@lists.php.net to get a copy of this message | ||
ID: 11472
Updated by: hholzgra
Reported By: webmaster@cd-lab.com
Old-Status: Open
Status: Closed
Bug Type: Feature/Change Request
Operating system:
PHP Version: 4.0.5
Assigned To:
Comments:
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 php-dev@lists.php.net 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
additional
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 ...
Previous Comments:
---------------------------------------------------------------------------
[2001-06-13 15:43:47] webmaster@cd-lab.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;
a();
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;
a();
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
CD-Lab
www.cd-lab.com
---------------------------------------------------------------------------
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=11472&edit=2