Req #7553 [Opn->Wfx]: RFC: Uplevel Block structure
| From: | jani@php.net | Date: | Wed, 01 Dec 2010 14:50:45 +0000 |
| Subject: | Req #7553 [Opn->Wfx]: RFC: Uplevel Block structure | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-156637@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=7553&edit=1
ID: 7553
Updated by: jani@php.net
Reported by: clcollie at mindspring dot com
Summary: RFC: Uplevel Block structure
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: Scripting Engine problem
Operating System: All
PHP Version: 4.0.3pl1
Block user comment: N
Private report: N
New Comment:
Cryptic, not PHP way, etc. Outdated as well.
Previous Comments:
------------------------------------------------------------------------
[2000-10-31 13:14:42] clcollie at mindspring dot com
Request For Comments: The Uplevel block structure
--------------------------------------------------
Very frequently it is useful to have a function perform actions which
would benefit from a better knowledge of its calling environment. This
would allow for more a more generic way of handling certain classes of
problems. Hopefully the following example will demonstrate :
Very often, i would like to do something like the following :
function export_script_vars( $var_names ) {
$result = "";
foreach ($var_names as $var_name) {
$result .= '<input type=hidden name="$var_name" value =
"${$var_name}"/><br>'
}
return $result;
}
The intent of the script is to generally handle the export of a script's
variables to hidden fields. The only problem, of course, is that the
function has access only to its own symbol table, so to do something
similar, we must resort to cut & past. This makes it impossible to have
a generic function to perform this task. i can easily imagine other
situations in which this occurs.
Proposal :
-----------
In TCL, there is the Uplevel syntax which allows a function to
temporarily change its symbol scope to that of its parents within a
program block. This instructs the interpreter to search one level up
for symbols unresolved in the current scope. The local symbol table
would still be seached first (though im not sure if TCL handles it that
way).
The syntax is similar to :
uplevel {
< Statements >
}
or
uplevel (level) {
< Statements >
}
where level is the number of stack levels to "pop". Personally, the
second option is not too important to me - the first would be fine.
With the proposed Uplevel syntax, the previous code would look like this
...
function export_script_vars( $var_names ) {
$result = "";
uplevel {
foreach ($var_names as $var_name) {
$result .= '<input type=hidden name="$var_name" value =
"${$var_name}"/><br>'
}
return $result;
}
}
With this addition, this opens great possibilities, though i can imagine
the need to also be cautious.
Thanks for making PHP the great tool it is!
cc
------------------------------------------------
"Fried Ice-Cream is a Reality!" - George Clinton
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=7553&edit=1