: : hey
: :
: : i was about making a little game in php when i came across something i don't like.
: :
: : i have an object (class) called player. and in the summoning class an array that is filled with player objects.
: :
: : filling the array:
: :
: : for ($i = 0; $i < $spelers; $i++) {
: : $this->_spelers[] = new Speler();
: : }
: :
: :
: : but later on:
: :
: : $this->_spelers[$i]->gooi();
: :
: :
: : does not work. it seems i cannot call methods/functions anymore.
: : a var_dump() shows the attributes/classvariables but no methods/functions.
: :
: : standard php 4 behaviour or not???
: :
: :
DarQ
: : Jou my no rap dy lekkere dikke tsjap
: :
:
: I use these things quite often and never had any problems...
:
:
: <?
: class Spel {
: var $Speler = Array();
:
: function Spel($AantalSpelers=2) {
: for ($i = 1; $i <= $AantalSpelers; $i++) {
: $this->Speler[$i] = new Speler();
: }
: }
: }
:
: class Speler {
:
: var $Naam;
: var $Score;
: var $LaatsteWorp;
:
: function Speler($naam="Anoniem") {
: $this->Naam = $naam;
: $this->Score = 0;
: }
:
: function Gooi($dobbelstenen=1) {
: $minimum = $dobbelstenen;
: $maximum = $dobbelstenen * 6;
:
: $this->LaatsteWorp = rand($minimum, $maximum);
:
: return $this->LaatsteWorp;
: }
:
: }
:
: // Start een spel met twee spelers
: $game = new Spel(2);
: print_r($game);
: // Speler een gooit met n dobbelsteen
: $game->Speler[1]->Gooi();
: // Speler 2 gooit met twee dobbelstenen
: $game->Speler[2]->Gooi(2);
:
: print_r($game);
:
: ?>
:
: output:
:
: spel Object
: (
: [Speler] => Array
: (
: [1] => speler Object
: (
: [Naam] => Anoniem
: [Score] => 0
: [LaatsteWorp] =>
: )
:
: [2] => speler Object
: (
: [Naam] => Anoniem
: [Score] => 0
: [LaatsteWorp] =>
: )
:
: )
:
: )
: spel Object
: (
: [Speler] => Array
: (
: [1] => speler Object
: (
: [Naam] => Anoniem
: [Score] => 0
: [LaatsteWorp] => 3
: )
:
: [2] => speler Object
: (
: [Naam] => Anoniem
: [Score] => 0
: [LaatsteWorp] => 9
: )
:
: )
:
: )
:
:

: -mac-
: mailto:mac_doggie@hotmail.com
: the Netherlands...
:
:
:
ah, i see you also use array[x]->classMethod(). so it is possible.
thnx, ill check it out
DarQ
Jou my no rap dy lekkere dikke tsjap