I've got a class which has two private arrays that are empty, but are each initialized in the constructor. I was having some problems for some reason and decided to do a var_dump. When I did that, I noticed each array was empty except for the functions they were declared in. I'm assuming this has to do with public/private/static which I've always had a hard time with (even through AP Computer Science this year). Any ideas?
In PHP arrays are dynamic so they don't have a "real" initialization except if you put the elements when you declare an array (they are dynamic anyway) In languages like C#, Java and others... arrays must be initialized with the array size: Code: //C# and Java int[] myarray = new int[10]; Then you can't add new elements to the array directly, you can only edit the existing elements. So in C# and Java you must use the List or Dictionary class. I don't understand your question well but if you can, post the code
I fixed it by changing the array variables to public static rather than private. Still not sure why it works and whether it is more/less secure, but it works
That means you are using classes incorrectly. @iksaku encountered this. Making it work isn't our goal. Making it work correctly is our goal. And it isn't related to static.
Heres the code: http://pastebin.com/pU7eBxRs I commented out where the var_dumps work and don't. If someone could point me in the right direction to fix this that would be great.
The var is $this->isRunning? You didn't initialize it in __construct. Maybe onPlayerDeath got triggered before start gets called?
Solved: I had registered this class as a listener in my main class, thus the static variable was the only one working because the event method was being called as a different instance of the class... This took me a day and a half to figure out...