+ -
当前位置:首页 → 问答吧 → 请教大家类里面调用函数的问题

请教大家类里面调用函数的问题

时间:2010-09-21

来源:互联网

复制代码
  1. class temp{
  2.     public $file;
  3.     public $lang=array();
  4.     function __construct($file=""){
  5.         $this->file=JZJD_ROOT.$file;//JZJD_ROOT是系统的绝对路径。
  6.     }
  7.     function tem($templates){
  8.         global $lang;
  9.         echo$this->file;
  10.         $str=@fopen($this->file,r);
  11.         $templates=@fread($str,filesize("$this->file"));
  12.         fclose($str);
  13.         $file='jzjd.tpl.php';
  14.         $this->langvar('gl');
  15.         $templates=preg_replace('/\{tem\s+(.*)\}/U',"<? require_once'\\1' ?>",$templates);
  16.         $templates=preg_replace('/\{lang\s+(.*)\}/U',$this->langvar('\\1') ,$templates);
  17.         $templates=preg_replace('/\{\if\((.*)\)\}/U','<? if(\\1){ ?>',$templates);
  18.         $templates=preg_replace('/\{\/if\}/U','<? } ?>',$templates);
  19.         $templates=preg_replace('/\{elseif\((.*)\)\}/U','<? } elseif(\\1){ ?>',$templates);
  20.         $fw=fopen("../templates/cache/$file",'w');
  21.         fwrite($fw,$templates);
  22.         fclose($fw);
  23.     }
  24.     function langvar($var){
  25.         include '../include/system.lang.php';
  26.         $lang=$lang[$var];
  27.         echo $lang;
  28.     }
  29.     function __destruct(){
  30.     }
  31. }

$templates=preg_replace('/\{lang\s+(.*)\}/U',$this->langvar('\\1') ,$templates);
这一句调用不了langvar函数。怎么回事?

作者: jzjd   发布时间: 2010-09-21

看着有点晕

作者: wxpcjrjgcs   发布时间: 2010-09-21

有报错吗? 按说是应该可以用的。。。$this-> 看看 报错情况

作者: 2008feixu   发布时间: 2010-09-21

作者: sufei   发布时间: 2010-09-21