Jump to content

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


praotes

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

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

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.

Link to post
Share on other sites
  • 3 months later...

"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.

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

Link to post
Share on other sites

Archived

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

×
×
  • 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.