Re: Passing a class through an array

From: Date: Thu, 15 Mar 2007 13:14:04 +0000
Subject: Re: Passing a class through an array
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-250656@lists.php.net to get a copy of this message
Ahh the problem was that I was using $name1->$name instead of $name1->name to call the variable. Thanks though :) > If line 140 is the $name1->name part, then you probably haven't > written your constructor correctly to cram 'Toon1' into the name > field... > > > On Thu, March 8, 2007 11:51 pm, Jeff Taylor wrote: > > Hey all, > > I'm very new to programming and PHP. > > I want to pass instances of a class through an array, and then use a > > foreach > > later to grab details of each class at once... but it returns a fatal > > error > > > > Code: > > > > $me = new Toon('Toon1','1') > > $him = new Toon('Toon2','0') > > > > $characterListing = array($me, $him); > > > > foreach ($characterListing as $name1) > > { > > if ($name1->GetIsPlayer()) > > { > > echo "<b>Name: </b> ".$name1->$name;//.... etc etc etc > > } > > } > > > > > > > > the error I get is: Fatal error: Cannot access empty property in > > c:\Inetpub\wwwroot\MyProjects\SecondOffering\htmlFns.php on line 140 > > > > Can anyone help? > > > > Thanks, Jeff > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > Some people have a "gift" link here. > Know what I want? > I want you to buy a CD from some starving artist. > http://cdbaby.com/browse/from/lynch > Yeah, I get a buck. So?

« previous php.general (#250656) next »