현재 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에서 일부 변경된 것을 알고 있습니다. 이것은 사이트 클래스의 모든 변수에 대한 설정자가 필요하다는 것을 말하고 있습니까? 각 변수마다 하나씩해야합니까, 아니면 일반적인 일입니까? 이러한 종류의 오류가 아니라 변수가 그것의 범위 밖으로에서 호출되는 것을 의미 않습니다
을 사용하는 방법? Smarty 라이브러리에서 어떤 기능을 호출합니까? – m13r