2017-05-10 64 views
1

我無法從php函數調用返回值。無法從類函數調用返回布爾值

  ... 
      $dey=$validate->yoxla($this->ad,$this->soyad,$this->istadi,$this->sifre,$this->email); 

      if($dey){ // i cant get returned value from here. even it is true. 
       echo 'asd'; 
       if(!$checkuser->checkusername($this->istadi)){ 
        $err=array(); 
        $err['code']='code14'; 
        $err['aciglama']=$code14; 
        print json_encode($err); 
        die(); 
       }elseif(!$checkuser->checkemail($this->email)){ 
        $err=array(); 
        $err['code']='code15'; 
        $err['aciglama']=$code15; 
        print json_encode($err); 
        die(); 
       }else{ 
        $err=array(); 
        $err['code']='acig'; 
        print json_encode($err); 
        die(); 
       } 
      } 

yoxla()函數:

 ... 
     elseif (!preg_match("/^.*(?=.{8,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*$/", $sifre)){ 
      $err=array(); 
      $err['code']='code11'; 
      $err['aciglama']=$code11; 
      print json_encode($err); 
      die(); 
     }elseif($email==""){ 
      $err=array(); 
      $err['code']='code12'; 
      $err['aciglama']=$code12; 
      print json_encode($err); 
      die(); 
     }elseif (!$this->validEmail($email)) { 
      $err=array(); 
      $err['code']='code13'; 
      $err['aciglama']=$code13; 
      print json_encode($err); 
      die(); 
     }else{ 
      return true; 
     } 

我調用由AJAX請求第一個。並沒有什麼返回ajax或我不能從getresult()函數返回值。

回答

2

從類聲明中刪除():

試試這個:

class Form{ 
    public function getresult(){ 
     return true; 
    } 
} 

$validate=new Form();  
$result=$validate->getresult(); 

if($result){ 
    echo 'true'; 
}else{ 
    echo 'false'; 
} 

啓用PHP錯誤日誌,這樣你可以在瀏覽器理解這樣的錯誤:http://php.net/manual/en/function.error-reporting.php

+0

問題更新。 –

+0

你應該第一次發佈正確的代碼,現在答案與問題不符。 – julekgwa

+0

Sory它是我的錯( –