2010-11-24 3 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이다()'두번째 인수로 폐쇄를 기대? – 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