Jump to content

Archived

This topic is now archived and is closed to further replies.

praotes

php5.5 preg_replace(): The /e modifier is deprecated, use preg_replace_callback

Recommended Posts

Dear Colleagues: 

 

We have upgraded our server to php5.5 and experience the following, as we run the Smarty template: 

 

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in xxx/xxxx/php5/smarty/base/Smarty_Compiler.class.php on line 270 

 

The code as it currently is reads this... 

 

/* replace special blocks by "{php}" */ 

$source_content = preg_replace($search.'e', "'" 

. $this->_quote_replace($this->left_delimiter) . 'php' 

. "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'" 

. $this->_quote_replace($this->right_delimiter) 

. "'" 

, $source_content); 

 

QUESTION: Can you please explain what I need to change. The code directly below is identical to the one above, EXCEPT I replaced preg_replace with preg_replace_callback. The php5.5 instructions say I need to replace the "replacement" param with specifying a "callback." I know too little of php to do this, nor do I find a clear cut "replacement" param in this code. 

 

$source_content = preg_replace_callback($search.'e', "'" 

. $this->_quote_replace($this->left_delimiter) . 'php' 

. "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'" 

. $this->_quote_replace($this->right_delimiter) 

. "'" 

, $source_content);

 

Hope you can assist. Thanks! 

 

Hans

Share this post


Link to post
Share on other sites

Upgrading to 5.5? Jumping the gun a bit much?

 

preg_replace('/expr/e', 'foo', $string)
is basically equivalent to

preg_replace_callback('/expr/', function($matches) {
    return foo;
}, $string)
where foo is actual PHP code. You also have to deal with closures and scope, though, so your code ends up looking something like

$self = $this;
$source_content = preg_replace_callback($search, function($matches) use ($self) {
	return $self->_quote_replace($self->left_delimiter)
	. "php"
	. str_repeat("\n", substr_count($matches[0], "\n")
	. $self->_quote_replace($self->right_delimiter)
}, $source_content);

Share this post


Link to post
Share on other sites

Dear Requinix:

 

Apologies for the late reply. I was called away yesterday.

 

Thanks for this coaching. We're merely working towards the future. PHP5.5 is supposed to be "stable" and PCI compliance seems to demand it. 

Thanks again,

 

Hans

Share this post


Link to post
Share on other sites

PHP5.5 is supposed to be "stable" and PCI compliance seems to demand it.

"Supposed". That's the point. I applaud you moving to 5.5, don't get me wrong there. I just find it surprising someone would move to a .0 release of PHP that's not even a month old.

 

PCI compliance probably wants you to be up to date with security patches. There's no way it could/should require you to be on the latest and greatest version of a product.

Share this post


Link to post
Share on other sites

"Supposed". That's the point. I applaud you moving to 5.5, don't get me wrong there. I just find it surprising someone would move to a .0 release of PHP that's not even a month old.

 

PCI compliance probably wants you to be up to date with security patches. There's no way it could/should require you to be on the latest and greatest version of a product.

 

 you can convey a point to someone more effectively by being a bit more down to earth. also i'm on php 5.5 as well, and still using preg with no problems. oddly enough, my ajax scripts seem to break with every upgrade, and the move to 5.5 was no exception.

Share this post


Link to post
Share on other sites

That's the point. I applaud you moving to 5.5, don't get me wrong there. I just find it surprising someone would move to a .0 release of PHP that's not even a month old.

5.5.0 was released in June, 5.5 is certainly stable and is currently at 5.5.5

Share this post


Link to post
Share on other sites

@r3wt, you do realize this thread is months old and statements made back in july about a newly released major version of software no longer apply?

Share this post


Link to post
Share on other sites

mac_gyver, i assumed he was talking about the minor subversion(5. 5.5). i didn't notice the thread was months old and he was referring to 5. 5.0 i do apologize for bumping this thread.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.