2013-08-25 1 views
0

최근에 php 버전이 5.3 인 웹 프로젝트를 완료 한 후이 프로젝트를 php 버전이 5.2. * 인 서버로 업로드합니다. 그런 다음 다음과 같은 메시지가 표시됩니다 :get_called_class in ph 5.2 *

Fatal error: Class name must be a valid object or a string in /home/user_folder/public_html/_includes/class.myclass.php on line 264 

을 내가 다음 코드 ::

protected function get_table_value($record) { 
    $className = get_called_class(); // 

    $object = new $className; // line 264 
    // rest of the code 
} 

를 사용 내 class.myclass.php에서 나는 다음과 같은 :

// get the database table's column's value 
    protected function get_table_value($record) { 
     $className = $this->generate_class_name(); 
     $object = new $className; // same error in this line 

     // rest of code 
    } 

    private function generate_class_name() { 

     if (!function_exists('get_called_class')) { 
      $bt = debug_backtrace(); 
      $l = count($bt) - 1; 
      $matches = array(); 
      while(empty($matches) && $l > -1){ 
       $lines = file($bt[$l]['file']); 
       $callerLine = $lines[$bt[$l]['line']-1]; 
       preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l--]['function'].'/', 
       $callerLine, 
       $matches); 
      } 
      if (!isset($matches[1])) $matches[1]=NULL; //for notices 
       if ($matches[1] == 'self') { 
       $line = $bt[$l]['line']-1; 
       while ($line > 0 && strpos($lines[$line], 'class') === false) { 
       $line--; 
      } 
      preg_match('/class[\s]+(.+?)[\s]+/si', $lines[$line], $matches); 
      } 
     return $matches[1];    
     } 
     else {     
      return get_called_class(); 
     }    
    } 
을로이 코드를 변경

그리고 이제 다시 오류 msg이옵니다. 모든 솔루션.

답변

0

질문이 명확하지 않습니다. Get_Class(); return 문에 입력 현재 클래스를 의지 VAR로 (그림 2 참조) : 다음은 매뉴얼에서 발췌 한 것입니다

그림 1

class foo { 
    function name() 
    { 
     echo "My name is " , get_class($this) , "\n"; 
    } 
} 

// create an object 
$bar = new foo(); 

// external call 
echo "Its name is " , get_class($bar) , "\n"; 

// internal call 
$bar->name(); 

그림 2

class foo{ 
    public function Test(){ 
    $Classname = get_class($this); 
    $Instance = new $Classname; 
    return $Classname; 
    } 
} 

아마도이 절차에 따라 기능을 수정하십시오.

+0

그것은 작동합니다. 많은 많은 감사 – sabbir