Skip to content

Instantly share code, notes, and snippets.

@AdarshAshwani
Created June 1, 2021 11:55
Show Gist options
  • Save AdarshAshwani/0a314523703f939966ed15036fbc7427 to your computer and use it in GitHub Desktop.
Save AdarshAshwani/0a314523703f939966ed15036fbc7427 to your computer and use it in GitHub Desktop.
<?php
class Car {
private $topSpeed;
function __construct($topSpeed) {
$this->topSpeed = $topSpeed;
}
public function drive() {
return "Driving at " . $this->topSpeed . " vrooms<br>";
}
}
$car1 = new Car(120);
echo $car1->drive();
// will raise an error if we try to access a private member
echo "Top speed for this car is " . $car1->topSpeed;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment