Skip to content

Instantly share code, notes, and snippets.

@bradsi
Last active March 25, 2021 16:08
Show Gist options
  • Save bradsi/707c9019e024ae868d30ee27130c83c5 to your computer and use it in GitHub Desktop.
Save bradsi/707c9019e024ae868d30ee27130c83c5 to your computer and use it in GitHub Desktop.
<?php
// Define a class
class User {
// Properties
public $name;
// Constructor - runs when an object is instantiated
public function __construct($name) {
echo 'Class ' . __CLASS__ . ' instantiated<br>';
$this->name = $name;
}
// Attributes
public function sayHello() {
return $this->name . ' Says Hello';
}
// Destructor - runs when we explicitly unset the object,
// when it goes out of bounds, and when the script ends
public function __destruct() {
echo 'destructor ran...';
}
}
// Instantiate a user object
$user1 = new User("Brad");
echo $user1->sayHello();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment