2010-11-24 11 views
0

イムラインの取得中にエラー4PHP関数エラーT_FUNCTION

解析エラー:構文エラー、Cでの予期せぬT_FUNCTION:\ xamppの\ htdocsにライン上の作業\ CASCの\管理者\フォーム-validator.php \ 21

誰でも助けることができますか?

public function email($message='') 
    { 
     $message = (empty ($message)) ? '%s is an invalid email address.' : $message; 
     $this->set_rule(__FUNCTION__, function($email) { 
      return (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) ? FALSE : TRUE; 
     }, $message); 
     return $this; 
    } 


private function set_rule($rule, $function, $message='') 
    { 
     // do not attempt to validate when no post data is present 
     if ($this->haspostdata) { 
      if (! array_key_exists($rule, $this->rules)) { 
       $this->rules[$rule] = TRUE; 
       if (! array_key_exists($rule, $this->functions) && is_callable($function)) { 
        $this->functions[$rule] = $function; 
       } 
       if (!empty ($message)) { 
        $this->messages[$rule] = $message; 
       } 
      } 
     } 
    } 
+0

は 'set_rule()'第2引数としてクロージャを期待しているのですか? – stillstanding

+4

PHP> = 5.3を使用していますか? – KingCrunch

+0

質問を編集しました。今すぐチェックしてください –

答えて

4

あなたのコードは完全に有効です。クロージャを使用するときに必要なPHP5.3を使用して実行していないようなエラーが表示されます。

だろう事前5.3方法:

private function emailRule($email) 
{ 
    return (filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) ? FALSE : TRUE; 
} 

public function email($message='') 
{ 
    $message = (empty ($message)) ? '%s is an invalid email address.' : $message; 
    $this->set_rule(__FUNCTION__, array($this, 'emailRule'), $message); 
    return $this; 
} 
+0

これは問題です。代替案は何ですか? –

+0

@ g.b .:合理的な選択肢はありません。 (NO! 'create_function'は代替ではありません!) – NikiC