Problems encountered in using anonymous functions in Preg_replace_callback

Source: Internet
Author: User
Keywords Php
Tags deprecated
After the recent upgrade of php5.3 to php5.6.19, a number of deprecated functions have occurred, such as: Deprecated:preg_replace (): the/e modifier is Deprecated, using Preg_replace_ Callback instead. So we started to modify it and replace it with Preg_replace_callback.
Certainly know the usage beforehand, but this is not the point. Now the problem is: when I'm done (post the changed code),

/* 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);

The result reported fatal error:using $this when the not in object context this error.
Here is the result of instantiating an object. The functions inside are also not static.
How to solve this problem?

The problem has been resolved, this involves PHP version, in the php5.4 above is no problem.

Reply content:

After the recent upgrade of php5.3 to php5.6.19, a number of deprecated functions have occurred, such as: Deprecated:preg_replace (): the/e modifier is Deprecated, using Preg_replace_ Callback instead. So we started to modify it and replace it with Preg_replace_callback.
Certainly know the usage beforehand, but this is not the point. Now the problem is: when I'm done (post the changed code),

/* 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);

The result reported fatal error:using $this when the not in object context this error.
Here is the result of instantiating an object. The functions inside are also not static.
How to solve this problem?

The problem has been resolved, this involves PHP version, in the php5.4 above is no problem.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.