I have something like this in PHP:
class
- mainfunction - function1 - function2
function1 and function2 are called from mainfunction. I need a value of a variable in function1 to pass to function2. They are no related so I can't pass as parameters.
I tried with $this->variable but the changes are not seeing in function2.
Thanks in advance.
In the class definition I used: var $piVarsList; Then in function1 I wrote: $piVarsList = $this->piVars;
When I debug in function1 using print_r($piVarsList); I see the $this->piVars data, 开发者_StackOverflowbut when I do that in function2 I don't see anything.
Thank you Glass Robot. I got the problem. The code in function1 and function2 render a web page so when the function2 is executed it is in new call of the code and function1 never is called.
I'm trying to store that data from the function1 in a different way instead of passing parameters in the URL because I'm using a cache function and it store a new page if the parameters in the URL are differents.
In your updated question your problem seams to be that you are assigning a local variable to the value of a class variable. You need to do it the other way round:
class ClassName
{
protected $a_variable;
public function function1()
{
// $variable can only be seen inside the method function1
$variable = 'stuff';
$this->a_variable = $variable;
// can also be written like this:
//$this->a_variable = 'stuff';
}
public function function2()
{
echo $this->a_variable;
}
}
精彩评论