4
- Script1.php
Here script1.php calls the function that is in script2:
sendData($variavel);
- Script2.php
The function takes the value and includes script 3 to receive argument values:
sendData(){
$getFirstArgumentValue = func_get_arg(0);
// $getVariableName = ...
sendVariableNameAndValue($getFirstArgument);
// global $variavel;
include('script3.php');
}
- Script3.php
In script3.php the variable called in script1.php is declared, and it is noticeable that an error message appears:
echo($variavel);
Error message appears in script3 warning that $variable has not been declared.
The question is:
How do I declare in script3, the same variable that was declared in script1, passing the function declared in script2 and receiving that value in script3?
In this case the sendData function would have to take the value of the argument and also the name of the variable used to send this value?
It would be possible to send the value and variable name?
Just out of curiosity, where would you wear this?
– gmsantos
I have detailed my answer better, see if any of the options fits your question...
– Jader A. Wagner
There are better solutions to pass arguments... if you can post what application you are doing
– Papa Charlie
As an alternative solution, I’m using an array.
$data['variavel']
, however it is still necessary to declare $data in script3.php. And I wanted to declare in script3.php, any variable that I want, but has the same name as the variable in script1.php– Slowaways
Describe the function of your page
script3.php
, what she does exactly... The example you gave is very superficial– Papa Charlie
Then use $GLOBALS['variable'] it is super global and does not need to be declared and will have the same value of $variable as script1.php
– Jader A. Wagner
user14319, a hint put all code!
– Maria