suppose i have the following code
function some_function($data)
{
// do something with data
}
$test = 'some_value';
some_function($test);
is there any way to access the var name '$test' from within the
function, i. e. can $data find out that $test is it's "parent"?
tia, micha 8 1208
micha wrote: suppose i have the following code
function some_function($data) { // do something with data }
$test = 'some_value';
some_function($test);
is there any way to access the var name '$test' from within the function, i. e. can $data find out that $test is it's "parent"? tia, micha
Don't think so... but why would you want to know that?
--
Virgil
Virgil Green wrote: micha wrote: suppose i have the following code
function some_function($data) { // do something with data }
$test = 'some_value';
some_function($test);
is there any way to access the var name '$test' from within the function, i. e. can $data find out that $test is it's "parent"? tia, micha Don't think so... but why would you want to know that?
--
well, i'm trying to write a function that automatically validates
arrays, i.e. $_POST, so i would need the original var name to report
back errors.
micha Virgil
micha wrote: Virgil Green wrote: micha wrote: suppose i have the following code
function some_function($data) { // do something with data }
$test = 'some_value';
some_function($test);
is there any way to access the var name '$test' from within the function, i. e. can $data find out that $test is it's "parent"? tia, micha
Don't think so... but why would you want to know that?
--
well, i'm trying to write a function that automatically validates arrays, i.e. $_POST, so i would need the original var name to report back errors.
micha Virgil
Then I'd suggest that your function have a second parameter that allows the
caller to pass in a string of identifying data that you use in the "report"
your function provides, or I'd have the function return the error messages
and allow the caller to format their own "report" of the errors since the
caller is aware of what variable was being validated.
--
Virgil
"micha" <ch*********@web.de> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com... Virgil Green wrote: micha wrote: > suppose i have the following code > > function some_function($data) > { > // do something with data > } > > $test = 'some_value'; > > some_function($test); > > is there any way to access the var name '$test' from within the > function, i. e. can $data find out that $test is it's "parent"? > tia, micha
Don't think so... but why would you want to know that?
--
well, i'm trying to write a function that automatically validates arrays, i.e. $_POST, so i would need the original var name to report back errors.
As the $_POST array is an associative array of name=value pairs then why
don't you do what I do and pass BOTH name and value to the validating
function.
--
Tony Marston http://www.tonymarston.net
Tony Marston wrote: "micha" <ch*********@web.de> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com... Virgil Green wrote: micha wrote: suppose i have the following code
function some_function($data) { // do something with data }
$test = 'some_value';
some_function($test);
is there any way to access the var name '$test' from within the function, i. e. can $data find out that $test is it's "parent"? tia, micha
Don't think so... but why would you want to know that?
--
well, i'm trying to write a function that automatically validates arrays, i.e. $_POST, so i would need the original var name to report back errors.
As the $_POST array is an associative array of name=value pairs then why don't you do what I do and pass BOTH name and value to the validating function.
I believe he wants the name of the array... "$_POST" in this case.
--
Virgil
If you use `global $test;` as a line inside the function it will allow
that function access to the var outside the function. if you did this
after you assigned it's passed-on variable to a different name, you
could compare the two non ?
yes, how stupid of me.
of course i can just use the names of the associative array.
sorry to have bothered everybody
micha
micha wrote: yes, how stupid of me. of course i can just use the names of the associative array. sorry to have bothered everybody
micha
I fail to see how that will accomplish your original goal. Or was the
original problem mis-stated (duplicated below)?
micha wrote: suppose i have the following code
function some_function($data) { // do something with data }
$test = 'some_value';
some_function($test);
is there any way to access the var name '$test' from within the function, i. e. can $data find out that $test is it's "parent"?
--
Virgil This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: Nick Coghlan |
last post by:
Time for another random syntax idea. . .
So, I was tinkering in the interactive interpreter, and came up with the
following one-size-fits-most default argument hack:
Py> x = 1
Py> def...
|
by: domeceo |
last post by:
can anyone tell me why I cannot pass values in a setTimeout function
whenever I use this function it says "menu is undefined" after th
alert.
function imgOff(menu, num) {
if (document.images) {...
|
by: Falc2199 |
last post by:
Hi,
Does anyone know how to make this work?
var sectionId = 5;
repeat_section_sectionId();
function repeat_section_5(){
alert("firing");
}
|
by: Michael Yanowitz |
last post by:
I am still new to Python but have used it for the last 2+ months.
One thing I'm still not used to is that functions parameters can't
change as expected. For example in C, I can have
status =...
|
by: Luke |
last post by:
I'm pretty stuck at the moment and wondering if anyone can spot the problem.
Trying to create a function that will read a text file into a list and
return that list.
I wrote the following...
|
by: Josiah Manson |
last post by:
I found that I was repeating the same couple of lines over and over in
a function and decided to split those lines into a nested function
after copying one too many minor changes all over. The only...
|
by: alex |
last post by:
I am so confused with these three concept,who can explained it?thanks
so much?
e.g.
var f= new Function("x", "y", "return x * y");
function f(x,y){
return x*y
}
var f=function(x,y){
|
by: David T. Ashley |
last post by:
I have this ugly habit of prefixing all function and variable names with
some identifying information about the owning module and perhaps also the
subcategory of function, i.e.
...
|
by: Christian Maier |
last post by:
Hi
After surfing a while I have still trouble with this array thing. I
have the following function and recive a Segmentation fault, how must
I code this right??
Thanks
Christian Maier
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |