How can I access properties in objects contained in an array?
Why does the code below doesn't work?
<?php class Car{ private $model; private $color; private $price; public function __car($model, $color, $price) { this.$model = $model; this.$color = $color; this.$price = $price; } } $cars = []; $jetta = new Car("Jetta", "Red", 2500); $cars[] = $jetta; $cobalt = new Car("Cobalt", "Blue", 3000); $cars[] = $cobalt; // this is the part of the code that doesn't work // I need to output the values from the objects, model, color and price echo $cars[0]->$model; echo $cars[0]->$color; echo $cars[0]->$price; Thanks
privatevisibility means.