PHP 5.5 and preg_replace function depracation
I don't suppose anyone has run into this bug using XAMPP with PHP 5.5 concerning the use of the preg_replace function. The code below comes to us from the Data_table file located in fuel/modules/fuel/libraries on or around line 913 in an editor.
$url = preg_replace('#^(.*)\{(.+)\}(.*)$#e', "'\\1'.((!empty(\$fields['\\2'])) ? \$fields['\\2'] : '').'\\3'", $val['url']);
The preg_replace function is deprecated and calls for the use of the preg_replace_callback function. Now I've never had much luck in writing regular expressions, much less updating one. I thought there might be an updated Data_table file on Github, but no such luck. Has anyone managed to get around the below error?
A PHP Error was encountered
Severity: 8192
Message: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead
Filename: libraries/Data_table.php
Line Number: 913
Comments
https://github.com/daylightstudio/FUEL-CMS/tree/1.0
//e modifier is deprecated if (version_compare(PHP_VERSION, '5.5', '>=')) { $url = preg_replace_callback('#^(.*)\{(.+)\}(.*)$#', function($match) use ($fields) { if (!empty($match[2])) { return $match[1].$fields[$match[2]].$match[3]; } return ''; }, $val['url']); } else { $url = preg_replace('#^(.*)\{(.+)\}(.*)$#e', "'\\1'.((!empty(\$fields['\\2'])) ? \$fields['\\2'] : '').'\\3'", $val['url']); }
protected function _render_actions($actions, $fields)
{
$str = '';
$actions = array();
foreach($this->_actions as $key => $val)
{
// normalize the data
if (!is_array($val))
{
$val = array('url' => $val);
}
if (!empty($val['func']))
{
$action = call_user_func($val['func'], $fields);
if (!empty($action)) $actions[] = $action;
}
else
{
// i love regexp... key is the e modifier that evaluates the code
//e modifier is deprecated
if (version_compare(PHP_VERSION, '5.5', '>='))
{
$url = preg_replace_callback('#^(.*)\{(.+)\}(.*)$#',
function($match) use ($fields) {
if (!empty($match[2]))
{
return $match[1].$fields[$match[2]].$match[3];
}
return '';
}, $val['url']);
}
else
{
$url = preg_replace('#^(.*)\{(.+)\}(.*)$#e', "'\\1'.((!empty(\$fields['\\2'])) ? \$fields['\\2'] : '').'\\3'", $val['url']);
}
$attrs = (!empty($val['attrs'])) ? ' '.$this->_render_attrs($val['attrs']) : '';
$actions[] =''.$key.'';
}
}
if (!empty($actions)) $str = implode(' '.$this->action_delimiter.' ', $actions);
return $str;
}
}
Filename: libraries/fuel_page.php
Line Number: 646
The code is:
$output = preg_replace('/(<body[^>]*>)/e', '"\\1\n".\$head_markers', $output);