-> Access Operator

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:

 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 properties

The $myBike object's single property, $make, has been assigned a value of: Ducati

Leave a Reply