在一个类中:使用函数调用函数

时间:2014-10-17 08:50:49

标签: php class methods

当我使用下面的代码时,我收到此错误:

Fatal error: Call to undefined function passwordHash() in 
C:\(...)\index.php on line 38

如果我做了$ something = new accountcreation;

并通过$ somethingn-> passwordHash();来调用它,我可以调用该函数。

但是,如何在班级内以我想要的方式调用该函数? (参见函数:callMethods();)

感谢。

class accountcreation {

    function __construct($passwordCreation, $userCreation, 
               $ipCreation, $emailCreation, $con) {
        $this->passwordCreation = $passwordCreation;
        $this->userCreation = $userCreation;
        $this->ipCreation = $ipCreation;
        $this->emailCreation = $emailCreation;
        $this->con = $con;

    }

     function callMethods() {
        passwordHash();
    }

     function passwordHash(){
        $this->passwordCreation = 
               password_hash($this->passwordCreation, PASSWORD_BCRYPT);
        var_dump($this->passwordCreation);
    }
}

1 个答案:

答案 0 :(得分:2)

$this->passwordHash()怎么样? :)与C ++相比,您必须明确指定this / $this

相关问题