::
is the scope resolution operator, used for accessing static
members of classes.
->
is the member operator, used for access members of objects.
Here's an example:
class Car {
public $mileage, $current_speed, $make, $model, $year;
public function getCarInformation() {
$output = 'Mileage: ' . $this->mileage;
$output = 'Speed: ' . $this->current_speed;
$output = 'Make: ' . $this->make;
$output = 'Model: ' . $this->model;
$output = 'Year: ' . $this->year;
return $output;
}
}
class CarFactory {
private static $numberOfCars = 0;
public static function carCount() {
return self::$numberOfCars;
}
public static function createCar() {
self::$numberOfCars++;
return new Car();
}
}
echo CarFactory::carCount(); //0
$car = CarFactory::createCar();
echo CarFactory::carCount(); //1
$car->year = 2010;
$car->mileage = 0;
$car->model = "Corvette";
$car->make = "Chevrolet";
echo $car->getCarInformation();