The -> (aka small arrow) access operator is used to get or set an object’s attributes.
This example show the -> access operator being used to set and get a properties values:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Access Operator" ><?php class Bike { public $make ; } echo "<h1>Using the -> access operator to set and get an object's properties</h1>"; $myBike = new Bike ; //SETTING the property value using the -> (small arrow) access operator $myBike->make = "Ducati" ; //$ sign is not required for variable when using -> echo "<p>The \$myBike object's single property, \$make, has been assigned a value of: "; //GETTING the property value using the -> (small arrow) access operator echo $myBike->make . "</p>"; ?> |
Save & refresh browser:
Using the -> access operator to set and get an object's propertiesThe $myBike object's single property, $make, has been assigned a value of: Ducati |