2014-10-17 79 views
0

當我使用下面的代碼,我得到這個錯誤:在類:調用函數與函數

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

如果我做的東西$ =新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); 
    } 
} 

回答

2

$this->passwordHash()怎麼樣? :)與C++相比,您總是必須明確指定this/$this

+0

那麼,這是無痛的....謝謝。 – icor103 2014-10-17 08:54:34