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이옵니다. 모든 솔루션.
그것은 작동합니다. 많은 많은 감사 – sabbir