Last active
March 25, 2021 16:08
-
-
Save bradsi/707c9019e024ae868d30ee27130c83c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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