За последние 24 часа нас посетили 18163 программиста и 1617 роботов. Сейчас ищут 1437 программистов ...

Помогите исправить ошибку

Тема в разделе "Сделайте за меня", создана пользователем sashamol, 28 мар 2019.

  1. sashamol

    sashamol Новичок

    С нами с:
    28 мар 2019
    Сообщения:
    3
    Симпатии:
    0
    Не кидайтесь плиз камнями, но сам я не знаю как исправить ошибку.

    Notice
    : Undefined property: template::$fors in /var/www/u0685127/data/www/ulibkaplus.tk/lib/tmpl.class.php on line 55
    Notice: Undefined offset: 1 in /var/www/u0685127/data/www/ulibkaplus.tk/lib/tmpl.class.php on line 55
    Notice: Undefined offset: 2 in /var/www/u0685127/data/www/ulibkaplus.tk/lib/tmpl.class.php on line 55
    Notice: Undefined offset: 3 in /var/www/u0685127/data/www/ulibkaplus.tk/lib/tmpl.class.php on line 55

    Код (Text):
    1. <?
    2.  
    3. class template {
    4.     private $root_path = '_SCRIPTS_PATH';
    5.     private $for;
    6.     private $fors;
    7.     private $content;
    8.  
    9.     public function __construct($file) {
    10.         if (file_exists($file))
    11.             $this->content = file_get_contents($file);
    12.         else
    13.             recordException("file: ".$file);
    14.     }
    15.  
    16.     public function _var($name, $value) {
    17.         $this->content = str_replace("{var:".$name."}", $value, $this->content);
    18.         //
    19.         $this->content = str_replace("[var:".$name."]", $value, $this->content);
    20.     }
    21.  
    22.     public function _uservar($name, $value) {
    23.         $this->content = str_replace("{uservar:".$name."}", $value, $this->content);
    24.         $this->content = str_replace("%uservar:".$name."%", $value, $this->content);
    25.     }
    26.  
    27.     public function _include($path, $filename, $convert=false) {
    28.         $file = $path.$filename.".tmpl";
    29.         if (file_exists($file)) {
    30.             $content = file_get_contents($file);
    31.             if ($convert)
    32.                 $content = toDBCharset($content);
    33.             $this->content = str_replace("{include:".$filename."}", $content, $this->content);
    34.         } else {
    35.             recordException("file: ".$file);
    36.         }
    37.     }
    38.  
    39.     public function _if($name, $cond=1) {
    40.         if ($cond) $this->content = preg_replace("/{if:".$name."}(.*?){\/if:".$name."}/is", "\\1", $this->content);
    41.         else $this->content = preg_replace("/{if:".$name."}(.*?){\/if:".$name."}/is", "", $this->content);
    42.     }
    43.     public function _userif($name,$v=1) {
    44.         if ($v) $this->content = preg_replace("/{userif:".$name."}(.*?){\/userif:".$name."}/is", "\\1", $this->content);
    45.         else $this->content = preg_replace("/{userif:".$name."}(.*?){\/userif:".$name."}/is", "", $this->content);
    46.     }
    47.     public function sFor($name) {
    48.         unset($this->fors);
    49.         $what = "{for:".$name."}(.*?){\/for:".$name."}";
    50.         preg_match("/".$what."/is", $this->content, $out);
    51.         $this->for = $out[1];
    52.     }
    53.  
    54.     public function vFor($idx, $name, $value) {
    55.         if ($this->fors[$idx])
    56.             $tmp = $this->fors[$idx];
    57.         else
    58.             $tmp = $this->for;
    59.      
    60.         $this->fors[$idx] = str_replace("{for-var:".$name."}", $value, $tmp);
    61.     }
    62.  
    63.     public function iFor($idx, $name, $cond=1) {
    64.         if ($this->fors[$idx])
    65.             $tmp = $this->fors[$idx];
    66.         else
    67.             $tmp = $this->for;
    68.      
    69.         if ($cond) $this->fors[$idx] = preg_replace("/{for-if:".$name."}(.*?){\/for-if:".$name."}/is", "\\1", $tmp);
    70.         else $this->fors[$idx] = preg_replace("/{for-if:".$name."}(.*?){\/for-if:".$name."}/is", "", $tmp);
    71.     }
    72.  
    73.     public function eFor($name) {
    74.         $tmp = (is_array($this->fors) ? implode("", $this->fors) : "");
    75.         $what = "{for:".$name."}(.*?){\/for:".$name."}";
    76.         $this->content = preg_replace("/".$what."/is", str_replace("$", "\\$", $tmp), $this->content);
    77.         unset($this->for);
    78.     }
     
  2. Maputo

    Maputo Активный пользователь

    С нами с:
    30 июл 2015
    Сообщения:
    1.136
    Симпатии:
    173
    В 48 строке
    PHP:
    1. unset($this->fors);
    Лучше заменить на
    PHP:
    1. $this->fors = [];
    И должно ли там быть fors или for?
     
  3. sashamol

    sashamol Новичок

    С нами с:
    28 мар 2019
    Сообщения:
    3
    Симпатии:
    0
    После замены 48 строчки и исчезла ошибка Notice: Undefined property: template::$fors, но остальные остались. Там должно быть fors.
     
  4. Maputo

    Maputo Активный пользователь

    С нами с:
    30 июл 2015
    Сообщения:
    1.136
    Симпатии:
    173
    Тогда остается заменить в 55 строке
    PHP:
    1. if ($this->fors[$idx])
    на
    PHP:
    1. if (isset($this->fors[$idx]))
     
    sashamol нравится это.
  5. sashamol

    sashamol Новичок

    С нами с:
    28 мар 2019
    Сообщения:
    3
    Симпатии:
    0
    Это типа тэст и fors отвечает за ответы, а for за вопрос и если убрать fors на for то ошибка пропадает, но и выбор ответов тоже.
    --- Добавлено ---
    Все получилось. Спасибо большое.