Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class User {
- /** @var string */
- protected $password;
- /**
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @param string $password
- */
- public function __construct(string $password)
- {
- $this->password = $password;
- }
- /**
- * @param string $password
- *
- * @return User
- */
- public static function create(string $password)
- {
- return new self($password);
- }
- /**
- * @param User $user
- * @param string $password
- */
- public function changePassword(User &$user, string $password)
- {
- $user = self::create($password);
- }
- }
- $user = User::create("pass1");
- print_r($user->getPassword());
- $user->changePassword($user, 'pass2');
- print_r($user->getPassword());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement