Notes: "preg_replace() /e modifier is deprecated slideshow_preprocess_views_slideshow()"

Patch to views_slideshow/theme/views_slideshow.theme.inc file as per (starting @ line# 69):

<?php
   
// Loop through all the addons and call their methods if needed.
   
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);
+         
$methods[$imp_key][] = preg_replace_callback(   // php5.x preg_replace_callback() method
+            '/_(.?)/',
+            function (
$m) {
+              return
strtoupper($m[1]);
+            },
+           
$addon_id
+          );
        }
        else {
-         
$methods[$imp_value][] = preg_replace('/_(.?)/e',"strtoupper('$1')", $addon_id);
+         
$methods[$imp_value][] = preg_replace_callback// php5.x preg_replace_callback() method
+            '/_(.?)/',
+            function (
$m) {
+              return
strtoupper($m[1]);
+            },
+           
$addon_id
+          );
        }
      }
    }
?>

Comments

I found that there were four places in this file that needed changing. The two already mentioned and then two more times where preg_replace was used. For me they were around lines 186 + 277.

At 186 and 277 I replaced

<?php
        $vars
['location'] => array(
         
'type' => preg_replace('/_(.?)/e',"strtoupper('$1')", $vars['settings']['type']),
        ),
?>

with

<?php
        $vars
['location'] => array(
         
'type' => preg_replace_callback(   // php5.x preg_replace_callback() method
           
'/_(.?)/',
            function (
$m) {
              return
strtoupper($m[1]);
            },
           
$vars['settings']['type']),
        ),
?>

StatusFileSize
new2.35 KB

I added a patch with all changes.

attached a patch that applies on 7.x-3.0 and resolve the issue.

Patch from #3 works like a charm for me. Please apply to git repo. Cheers!

Hi Marc

On which line does this patch start?

Status:Needs review» Reviewed & tested by the community

Patch from #3 works just fine (tested with PHP5.4 and 5.5)

Status:Reviewed & tested by the community» Needs work

Sorry, that was too early. Under PHP 5.2, patched views_slideshow fails with 'Unexpected T_FUNCTION'

patch worked great for me...thanks! Marc Angles++

Status:Needs work» Fixed

Thanks Marc Angles, alexandermeindl, Peter Bowey
commit: 1a041a4

Status:Fixed» Needs work

Patch breaks PHP 5.2 (no anynimous functions support, syntax error).

Assigned:Unassigned» xiukun.zhou

Status:Needs review» Needs work
StatusFileSize
new3.07 KB

Thanks very much valthebald.
i have create a patch to fix the bug. tested by http://sandbox.onlinephpfunctions.com/. work to me

Status:Needs work» Needs review

There's extra space in the end of line 255, otherwise, patch looks really great
Thanks!

Status:Needs work» Active

Thanks very much valthebald, i have adopted your advise and made some change.
commit:
d9fd60c

Oh. sorry,there is an extra space,i will fix it next push

Status:Active» Fixed

Automatically closed -- issue fixed for 2 weeks with no activity.

#3测试成功,十分感谢分享