2017-03-14 1 views
0

현재 PHP5 및 Smarty 2.6에서 PHP7 및 Smarty 3.1.31로 업그레이드 된 일부 사이트를 업그레이드하려고합니다. 변수 범위가 php5/smarty2.6에서 php7/smarty3.1로 변경되었습니다.

class Site extends WebView 
{ 
    //functions 
} 

class WebView extends LandingPage 
{ 
    //functions 
} 

class LandingPage extends Smarty 
{ 
    function LandingPage() 
    { 
     $this->sessionInit = false; 

     $this->flag = array(); 
     $this->engineVersion = ''; 

     $this->charset = 'utf-8'; 
     $this->content_type = 'text/html'; 
     $this->strings = array(); 
     $this->rtid=null; 
    } 
} 

이이 점에서 모든 변수를 잘 일 전에

$this->variable_name를 사용하여 정확하게 위치했다 :

우리는 이전에 다른 클래스를 확장 클래스 시스템과 사이트를했다, 여기의 단순화 된 버전입니다 . 내부 클래스에서 $this->flag['TEST'] 같은 $ this를 직접 사용하여 액세스하거나 외부에서 $site->flag['TEST']과 같은 $site을 사용할 수 있습니다. 그러나, 이제 나는 정의되지 않은 속성 오류

Notice: Undefined property: Site::$sessionInit in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 
Notice: Undefined property: Site::$flag in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 
Notice: Undefined property: Site::$engineVersion in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 
Notice: Undefined property: Site::$charset in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 
Notice: Undefined property: Site::$content_type in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 
Notice: Undefined property: Site::$strings in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 
Notice: Undefined property: Site::$rtid in /var/www/html/vendor/smarty/smarty/libs/Smarty.class.php on line 1447 

내가 (분명 내가 이것을 작성하지 않은) 스마티 클래스에 들어갔다 시리즈를 받고 일반 세터가 라인 1447에 대한 기능, 밖으로 잡고 있어요 :

/** 
* <<magic>> Generic setter. 
* Calls the appropriate setter function. 
* Issues an E_USER_NOTICE if no valid setter is found. 
* 
* @param string $name property name 
* @param mixed $value parameter passed to setter 
*/ 
public function __set($name, $value) 
{ 
    if (isset($this->accessMap[ $name ])) { 
     $method = 'set' . $this->accessMap[ $name ]; 
     $this->{$method}($value); 
    } elseif (in_array($name, $this->obsoleteProperties)) { 
     return; 
    } else { 
     if (is_object($value) && method_exists($value, $name)) { 
      $this->$name = $value; 
     } else { 
      trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); 
     } 
    } 
} 

어디서나 사용 가능하므로 문제가 없다고 생각합니다. 오류가 발생하는 이유는 오류가 Site::$sessionInit을 참조하는 것과 같습니다. 변수가 사이트의 사이트 여야하고, 방문 페이지에서 설정하려고 할 때 화가 날 것입니다.

가변 범위가 php7에서 일부 변경된 것을 알고 있습니다. 이것은 사이트 클래스의 모든 변수에 대한 설정자가 필요하다는 것을 말하고 있습니까? 각 변수마다 하나씩해야합니까, 아니면 일반적인 일입니까? 이러한 종류의 오류가 아니라 변수가 그것의 범위 밖으로에서 호출되는 것을 의미 않습니다

+0

을 사용하는 방법? Smarty 라이브러리에서 어떤 기능을 호출합니까? – m13r

답변

0
Notice: Undefined property: Site::$sessionInit in /var/www/html/vendor .... 
.... 
.... 

(유식 이미 작동하지 않는 일반적인있다처럼 보인다).

이것은 어디에도 정의되지 않은 변수를 호출하려고한다는 것을 의미합니다.

과이 문제를 해결하기 위해, 당신은 단순히 다음과 같이 그 변수를 정의해야합니다 클래스가 멋지와

class LandingPage extends Smarty 
{ 
    public $sessionInit; 
    public $flag; // or what ever the right visibility term 
    // .... and so on 
    function LandingPage() 
    { 
     $this->sessionInit = false; 

     $this->flag = array(); 
     $this->engineVersion = ''; 

     $this->charset = 'utf-8'; 
     $this->content_type = 'text/html'; 
     $this->strings = array(); 
     $this->rtid=null; 
    } 
} 
+0

나는 이것을 시험해 보겠다. 이것은 php5가 매우 용서하고 php7이 앱을 매우 명백하게하기를 원한다면 이전에 찾지 못했을 때 애플리케이션을 대신하여 변수를 선언하는 기능입니다. – Josh

+0

필자는 그렇게 생각하지 않는다. php.ini 파일에서'display_errors'를 no로 설정하여이주의 사항을 숨길 수 있습니다. – hassan

관련 문제