Re: arrays as object properties

From: Date: Thu, 26 Oct 2000 07:50:07 +0000
Subject: Re: arrays as object properties
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-22053@lists.php.net to get a copy of this message
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 > >

« previous php.general (#22053) next »