Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User {
- private $name; // Class Member Property
- private static $users = array( // Class Property
- 1=>array(
- "fname" => "Ted",
- "lname"->"Mosby"),
- 2=>array(
- "fname" => "Robin",
- "lname"->"Scherbatsky")
- );
- public function GetName() { // Class Member Method
- return $this->name;
- }
- public static function GetFirstName($id) { // Class Method
- return self::$users[$id]["fname"];
- }
- public function __construct($name) { // Constructor
- $this->name = $name;
- }
- }
- To access a class member method, a new instance of the class has to be created:
- $user = new User("Robin"); // <- Class member - Is an instance of the class User
- echo $user->GetName(); // Call of a class member method
- /* prints: Robin */
- To access a class method, a reference to the class has to be used:
- var_dump(User::GetFirstName(1));
- /* prints: Ted */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement