1

我正在编写一个邮件模板系统。用户应该能够在那里使用标记,它们将被实际数据替换。问题在于,我替换标记的函数工作得很好,但我需要对该函数进行递归调用,它只会运行一次,这就是我想出的:

public function replace_placeholders($content, $recipient, $settings, $interface, $recommendation, $format, $recursion = false) {
    $content = $this->replace_ph('briefanrede'  , $recipient['id']          , $content);
    $content = $this->replace_ph('anrede'       , $recipient['title']       , $content);
    $content = $this->replace_ph('email'        , $recipient['email']       , $content);
    $content = $this->replace_ph('kundennummer' , $recipient['kdnumber']    , $content);
    $content = $this->replace_ph('briefanrede'  , $recipient['briefanrede'] , $content);

    if($recipient['title'] == $settings['anrede_w'] || $recipient['title'] == $settings['anrede_m']) {
        $content = $this->replace_ph('vorname'  , $recipient['forename']    , $content);
        $content = $this->replace_ph('nachname' , $recipient['surename']    , $content);
    } else {
        $content = $this->replace_ph('vorname'  , ""    , $content, true);
        $content = $this->replace_ph('nachname' , ""    , $content, true);
    }

    $content = $this->replace_salutation($recipient, $settings, $content);

    //Recommendation    
    if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) {
        if($recommendation['own_page'] == 1) {
            $baseurl = $recommendation['location'];
        }  else {
            $baseurl = $recommendation['link'];
        }
        $pattern = ($format == "html") ? '<a href="%s">%s</a>' : '%s';
        $url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);
        $content = $this->replace_ph('weiterempfehlung' , (($format == "html") ? sprintf($pattern, $url, $settings['text_weiterempfehlung']): sprinf($pattern, $url)), $content);

    }

    return $content;
}

此行中的递归调用

$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true);

导致 500 内部服务器错误。我不知道为什么,因为我认为我将递归限制为运行一次。你能帮我吗?

对不起,我的英语不好,我努力写出清晰的句子。

//编辑:

阿帕奇日志:

[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function
[Wed May 30 15:31:56 2012] [error] [client xx.xxx.xx.xxx] File does not exist: /var/www/web80/html/web80-newsletter/favicon.ico
[Wed May 30 15:31:58 2012] [error] mod_fcgid: process /var/www/php-fcgi/web80.php53/php-fcgi(21975) exit(communication error), get unexpected signal 11 

php 错误日志为空。

4

2 回答 2

1

似乎您在递归调用中错过了一个参数,使$recursive = falsecontinue 始终为假,这反过来又使您的 if 语句

if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false)

总是返回真。尝试将最后一个变量添加到您的递归调用中,您应该能够正确执行您的脚本,即:

$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, 
$recommendation, true, true);
                     ^ added one true

我认为您要添加而不是第一个 true 的是$format.

于 2012-05-31T07:57:14.637 回答
0

信号 11 是 SIGSEGV,即进程由于错误的内存访问而崩溃(例如取消引用 NULL 指针或访问它不应该访问的内存)。

这不是 PHP 脚本应该引起的,因此您应该首先升级到最新的稳定 PHP 版本,如果仍然发生,请尽可能减少您的脚本(删除在崩溃仍然发生时可以删除的所有内容)然后报告它是一个 PHP 错误。

于 2012-05-31T07:50:41.547 回答