-1
In the function below I receive a message that the form used is not safe... and even ignoring I am unable to collect the contents of the variable $a
after function
$a = array();
function teste1(){
global $a;
$a[] = "Ola";
$a[] = "Passei";
$a[] = "Por";
$a[] = "Aqui";
}
function teste2(){
global $a;
$a[] = "Também";
$a[] = "Passei";
$a[] = "Por";
$a[] = "Aqui";
}
var_dump($a); // Aqui esta vindo vazia
This is a basic example, in the real world the function involves several layers that per hour would be impossible to return $a
how to Return the test function.
I need to log and I need to fill the array with several strings throughout the process and at the end write a text file, but at that point my problem is to declare a variable that can be used outside the function, because it goes through several functions.
Your question opens a range of solutions, it is no use to us to answer what is there, everything is assumption, maybe what you also intend to do is not the best solution, access a global variable is not always a good way, everything depends, everything depends also on context, time, place and form. The bad thing about these questions is that they don’t portray your real problem but always assumptions and this goes against the site.
– novic
I get it... but look at this, I have an old complex system that I can’t just rewrite... for now I would need a global array variable to debug
– Marcelo
You now edited and put more information, face without having a logical study pass the variable
$a
by reference or return at the end over the old values.– novic
Marcelo you put a variable at the beginning of
script
you have access to the end, so face depends on how this system is done is a page with everything, I really asked for more clarification on your question because this is not how it should be done.– novic