Advertisement
brandizzi

Private properties are not visible.

Oct 25th, 2016
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. <?php
  2. // cf. http://stackoverflow.com/questions/40230045/why-should-i-declare-the-class-property-in-php
  3. class account {
  4.     private $username;
  5.     private $password;
  6.     public function __construct($username, $password) {
  7.         $this->username = $username;
  8.         $this->password = $password;
  9.     }
  10.     public function getPassword() {
  11.         return str_repeat('*', strlen($this->password));
  12.     }
  13. }
  14.  
  15. $a = new account('brandizzi', 'MySecretPassword');
  16.  
  17. echo $a->getPassword() . "\n";
  18. echo $a->password . "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement