Private properties are not visible.
<?php
// cf. http://stackoverflow.com/questions/40230045/why-should-i-declare-the-class-property-in-php
class account {
private $username;
private $password;
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