RE: [PHP] arrays as object properties
| From: | Grant Walters | Date: | Wed, 25 Oct 2000 20:44:17 +0000 |
| Subject: | RE: [PHP] arrays as object properties | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21928@lists.php.net to get a copy of this message | ||
> Try putting global $parts in your init function.
>
>
> 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;
>
> //the following peice of code is the trouble......i can't seem to make an
> object property an array....
> $car->init($parts);
Try this
class car {
var $parts;
function car($new_parts) {
$this->parts = $new_parts;
}
}
$newcar = new car($parts);
Regards
Grant Walters
Walters & Associates, P O Box 13-043 Johnsonville, Wellington, NEW ZEALAND
Telephone: +64 4 4765175, CellPhone 025488265