最近升級php5.3到php5.6.19後,出現了一些棄用函數,比如:Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead。於是就著手修改,將其替換為preg_replace_callback。
事先當然瞭解一下其用法,但這個不是重點。當下出現的問題是:我改好後(貼出改完的代碼),
/* replace special blocks by "{php}" */ $source_content = preg_replace_callback($search, function ($r) { $str = $this->_quote_replace($this->left_delimiter); $str .= 'php'; $str .= str_repeat("\n", substr_count($r[0], "\n")); $str .= $this->_quote_replace($this->right_delimiter); return $str; }, $source_content);
結果報Fatal error: Using $this when not in object context這個錯誤。
這裡是執行個體化一個對象的結果。裡面的函數也都不是靜態。
如何解決這個問題?
問題已解決,這個涉及到php的版本,在php5.4以上就沒問題了。
回複內容:
最近升級php5.3到php5.6.19後,出現了一些棄用函數,比如:Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead。於是就著手修改,將其替換為preg_replace_callback。
事先當然瞭解一下其用法,但這個不是重點。當下出現的問題是:我改好後(貼出改完的代碼),
/* replace special blocks by "{php}" */ $source_content = preg_replace_callback($search, function ($r) { $str = $this->_quote_replace($this->left_delimiter); $str .= 'php'; $str .= str_repeat("\n", substr_count($r[0], "\n")); $str .= $this->_quote_replace($this->right_delimiter); return $str; }, $source_content);
結果報Fatal error: Using $this when not in object context這個錯誤。
這裡是執行個體化一個對象的結果。裡面的函數也都不是靜態。
如何解決這個問題?
問題已解決,這個涉及到php的版本,在php5.4以上就沒問題了。