brandizzi icon

Undeclared property is public by default.

brandizzi | PRO | 10/25/16 05:52:15 PM UTC | 0 ⭐ | 768 👁️ | Never ⏰ | []
PHP |

470 B

|

None

|

0 👍

/

0 👎

<?php
// cf. http://stackoverflow.com/questions/40230045/why-should-i-declare-the-class-property-in-php
class account {
    public function __construct($username, $password) {
        $this->username = $username;
        $this->password = $password;
    }
    public function getPassword() {
        return str_repeat('*', strlen($this->password));
    }
}
 
$a = new account('brandizzi', 'MySecretPassword');
 
echo $a->getPassword() . "\n";
echo $a->password . "\n";

Comments