I'm working on a website that creates an object called player that can contain any number of event objects that get added to the player object from an event-driven xml parser. So what I've been trying to do is use an array but that does not working, from my understanding this is because arrays must be constructed at object creation. So anyone have any alternative ideas or thoughts on what I missed?

<?php 

class player {
	//removed unrelated variables
	var $attendance;

	//removed unrelated functions
	function player() { }
	
	function addEvent(&$event) {
		$this->attendance[] = $event;
	}
}
?>

Someone else already said it better than I could...

http://www.daniweb.com/forums/thread130759.html

Ya, I've been over that post several times. It doesn't help too much with my situation since in his code he passed in the array when he instanced the object and also provided an example of accessing a global array.

Neither of which work for what I am working on. As I mentioned I need to add elements to an array inside of an already instanced object. I could achieve the same effect by implementing a linked list data structure inside the object, however I would hate to do that only to find out later that an array will work and I just used it wrong. Which brings me back to the topic:
Is there anyway to add additional elements to an array inside of an already instanced object?

Then you need it to be global and static?
If you are doing stuff on the fly, wouldn't Javascript be a better choice?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.