<?php namespace models; class User{ private $login=""; private $password=""; public function getId() { return $this->id; } public function setId($id) { $this->id=$id; return $this; } public function getLogin() { return $this->login; } public function setLogin($login) { $this->login=$login; return $this; } public function getPassword() { return $this->password; } }
use models\User; $aUser=new User();
<?php namespace use models; class User{ private $login=""; private $password=""; public function __construct($login="",$password=""){ } ...
Pas de surcharge, mais paramètres optionnels
<?php use models\User; $user1=new User(); $user2=new User("fred"); $user3=new User("fred","azerT1yuiop");
Opérateur →
<?php use models\User; $user=new User("Fred"); echo $user->getLogin();
Mot clé extends
<?php class Admin extends User{ ... }
parent::
<?php class Admin extends User{ public function __construct(){ parent::__construct(); ... } }
<?php class Utilitaire{ public static function show($user){ ... } }
Appel de méthode statique dans la classe
<?php class Utilitaire{ public function test($user){ ...self::show($user); } }
Appel de méthode statique en dehors de la classe
<?php use models\User; $aUser=new User("fred"); Utilitaire::show($user);