1
I’m creating some classes in php
and I have the following question:
for methods get
and set
in php
, I rode as follows:
class User
{
private $username = '';
private $password = '';
public function setPassword($password){
$this->password = encript($password);
}
public function getPassword(){
return $this->password;
}
function encript($data){
return sha1($data);
}
}
but when I call it so $user->setPassword(1234)
of error função encript() não definida
, where is the mistake? I don’t know much about php
but I’ve done it this way in other language and it usually works, what’s the problem?
weird, but thanks, it worked!
– Hebert Lima
@Hebertdelima without the
$this
PHP thinks you are calling a functionencript()
outside the class, this abbreviation that you quoted in the question works in other languages like java for example, in PHP the syntax gets a little longer :P– rray