In my local apache2 server I have PHP Version 5.5.12-2.
I am getting this error:

Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in views_slideshow_preprocess_views_slideshow() (line 73 of /var/www/html/sirate/sites/all/modules/views_slideshow/theme/views_slideshow.theme.inc).


I have same error on lines 76, 187, and 275.
Here is error in lines 73 through 76:

foreach ($addons as $addon_id => $addon_info) {
foreach ($addon_info['accepts'] as $imp_key => $imp_value) {
if (is_array($imp_value)) {
$methods[$imp_key][] = preg_replace('/_(.?)/e',"strtoupper('$1')", $addon_id);
}
else {
$methods[$imp_value][] = preg_replace('/(.?)/e',"strtoupper('$1')", $addon_id);
}
}
}


Here is line 187:

function theme_views_slideshow_pager_widget_render($vars) {
// Add javascript settings for the pager type.
$js_vars = array(
'viewsSlideshowPager' => array(
$vars['vss_id'] => array(
$vars['location'] => array(
'type' => preg_replace('/_(.?)/e',"strtoupper('$1')", $vars['settings']['type']),
),
),
),
);


Here is line 275:

function theme_views_slideshow_controls_widget_render($vars) {
// Add javascript settings for the controls type.
$js_vars = array(
'viewsSlideshowControls' => array(
$vars['vss_id'] => array(
$vars['location'] => array(
'type' => preg_replace('/_(.?)/e',"strtoupper('$1')", $vars['settings']['type']),
),
),
),
);


Please help, thank you.

    As the error message says, use [man]preg_replace_callback[/man] instead.

      Take a look at the [man]preg_replace_callback[/man] manual page, in particular example #1.

        I read the manual before posting but since I am at the starting point with PHP could not make much sense of it.
        So I am now posting the file that needs patching, I would appreciate if somebody would be so kind as to fix this file.
        I will then compare both versions and learn how to do it, thanks.

        views_slideshow.theme.inc.zip

          Firstly, notice that you are doing the same exact process in several places, which is begging for putting that code into a function in just one place (part of the don't repeat yourself [DRY] principle). Then, following the preg_replace_callback() manual/example, I'd define the function as:

          function fixCase($string)
          {
              return preg_replace_callback(
                  '/_(.?)/',
                  function($matches)
                  {
                      return(strtoupper($matches[1]);
                  },
                  $string
              );
          }
          

          If you stick that function definition into your script (or an include file included by the script), then all you have to do where you want to apply that change is just call the function:

          if (is_array($imp_value)) {
              $methods[$imp_key][] = fixCase($addon_id);
          }
          

            Thank you so much, NogDog.
            I was attempting to fix a Drupal distro that has not been updated in a while and relies on earlier versions of PHP.
            A simple replacement of the file that I was tinkering with for a newer version solved the problem.
            But, it will be a very interesting learning exercise to compare files against each other and your solution.

              Write a Reply...