Problems with using anonymous functions in preg_replace_callback

Source: Internet
Author: User
Some discarded functions, such as Deprecated: preg_replace (): Theemodifierisdeprecated and usepreg_replace_callbackinstead, appeared after php5.3 was upgraded to php5.6.19 recently. So I started to modify it and replaced it with preg_replace_callback... some discarded functions, such as Deprecated: preg_replace (): The/e modifier is deprecated and use preg_replace_callback instead, appear after php5.3 is upgraded to php5.6.19 recently. So we started to modify it and replaced it with preg_replace_callback.
Of course, I want to know its usage in advance, but this is not the focus. The problem that arises now is: After I modify the code (post the modified 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);

Fatal error: Using $ this when not in object context is returned.
Here is the result of instantiating an object. The functions are not static either.
How can this problem be solved?

The problem has been solved. If php version is involved, it will be okay in php5.4 or above.

Reply content:

Some discarded functions, such as Deprecated: preg_replace (): The/e modifier is deprecated and use preg_replace_callback instead, appear after php5.3 is upgraded to php5.6.19 recently. So we started to modify it and replaced it with preg_replace_callback.
Of course, I want to know its usage in advance, but this is not the focus. The problem that arises now is: After I modify the code (post the modified 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);

Fatal error: Using $ this when not in object context is returned.
Here is the result of instantiating an object. The functions are not static either.
How can this problem be solved?

The problem has been solved. If php version is involved, it will be okay in php5.4 or above.

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.