I need to have a variable that only one function can write (let’s call that function a) and that only one other function can read (let’s call that function b). Is that possible?
I need to have a variable that only one function can write (let’s call
Share
You could use a static variable:
Here
$varis only visible inside the functionfooand is maintained throughout multiple calls:Or use a class with a private member and access/modify it with public methods:
With this the private member var is only visible to a particular instance of this class:
If you make the member static, then there is just one for the class instead of for each instance: