Advertisement
brandizzi

Undeclared property is public by default.

Oct 25th, 2016
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 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.     public function __construct($username, $password) {
  5.         $this->username = $username;
  6.         $this->password = $password;
  7.     }
  8.     public function getPassword() {
  9.         return str_repeat('*', strlen($this->password));
  10.     }
  11. }
  12.  
  13. $a = new account('brandizzi', 'MySecretPassword');
  14.  
  15. echo $a->getPassword() . "\n";
  16. echo $a->password . "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement