Re: arrays as object properties

From: Date: Thu, 26 Oct 2000 15:02:20 +0000
Subject: Re: arrays as object properties
Groups: php.general 
Request: Send a blank email to php-general+get-22146@lists.php.net to get a copy of this message
Hi, Yes that's fine... even without var $parts; it would have worked... i tried it.... it would print 'Array' if you access $chevy->parts;\ hence you'll have to loop through the thing! --- Rebecca <rebecca@digitalpulp.com> wrote: > i got it like this: > > class car > { > var $parts = new array(); > function car($new_parts) > { > $this->parts = $new_parts; > } > } > > > and in my code: > > //where parts is a multidimensional array > $chevy = new car($parts); > > > > > ----- Original Message ----- > From: "Mukul Sabharwal" <mukulsabharwal@yahoo.com> > To: "Dallas Kropka" <dallask@firstworld.net>; > <php-general@lists.php.net> > Sent: Thursday, October 26, 2000 5:59 AM > Subject: Re: [PHP] arrays as object properties > > > > Hi, > > > > Dallas.... $parts[]; is not necessary..... what i > > think she wants to do is, see what the output is > > hence... it has to be ... > > > > for ($i = 0; $i < sizeof($car->parts); $i++) { > > > > echo $car->parts[$i]."\n"; > > > > } > > > > i think $parts[]; won't make a difference..... but > > anyway! > > > > --- Dallas Kropka <dallask@firstworld.net> wrote: > > > > First you need a constructor for your class > > > (function with the same name as > > > the class) > > > > > > > > > class car > > > { > > > var $parts[]; > > > function car($new_parts) > > > { > > > $this->parts = $new_parts; > > > } > > > } > > > > > > in your code > > > > > > $parts = > array("radio","four_w_drive","mats","si"); > > > $car = new car($parts); > > > > > > > > > the $car = new car($parts) Line will (should) > send > > > the array to the > > > constructor and set your array. > > > > > > I havent tested that, and some syntax could be > > > off... but it should work. > > > > > > NOTE: if I am off in my syntax, anyone feel free > to > > > correct me. > > > > > > ----- Original Message ----- > > > From: "Rebecca" <rebecca@digitalpulp.com> > > > To: <php-general@lists.php.net> > > > Sent: Monday, October 23, 2000 10:29 AM > > > Subject: [PHP] arrays as object properties > > > > > > > > > > so if i have: > > > > > > > > class car { > > > > > > > > var $parts; > > > > > > > > function init($new_parts) { > > > > $this->parts = $new_parts; > > > > } > > > > } > > > > > > > > how can i make this work: > > > > > > > > $parts = > > > array("radio","four_w_drive","mats","si"); > > > > $car = new car; > > > > > > > > file://the following peice of code is the > > > trouble......i can't seem to > > > make an > > > > object property an array.... > > > > $car->init($parts); > > > > > > > > > > > > -- > > > > PHP General Mailing List (http://www.php.net/) > > > > To unsubscribe, e-mail: > > > php-general-unsubscribe@lists.php.net > > > > For additional commands, e-mail: > > > php-general-help@lists.php.net > > > > To contact the list administrators, e-mail: > > > php-list-admin@lists.php.net > > > > > > > > > > > > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: > > > php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: > > > php-general-help@lists.php.net > > > To contact the list administrators, e-mail: > > > php-list-admin@lists.php.net > > > > > > > > > ===== > > To Find Out More About Me : http://mukul.tsx.org/ > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! Messenger - Talk while you surf! It's > FREE. > > http://im.yahoo.com/ > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: > php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: > php-general-help@lists.php.net > > To contact the list administrators, e-mail: > php-list-admin@lists.php.net > ===== To Find Out More About Me : http://mukul.tsx.org/ __________________________________________________ Do You Yahoo!? Yahoo! Messenger - Talk while you surf! It's FREE. http://im.yahoo.com/

« previous php.general (#22146) next »