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


    // 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
+          );
        }
      }
    }

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

VenDG’s picture

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

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

with

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

FileSize
2.35 KB

I added a patch with all changes.

Marc Angles’s picture

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

Anonymous’s picture

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

@Kambiyaso’s picture

Hi Marc

On which line does this patch start?

valthebald’s picture

Status: Needs review » Reviewed & tested by the community

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

valthebald’s picture

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'

scotwith1t’s picture

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

xiukun.zhou’s picture

Status: Needs work » Fixed

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

valthebald’s picture

Status: Fixed » Needs work

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

xiukun.zhou’s picture

Assigned: Unassigned » xiukun.zhou
xiukun.zhou’s picture

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

xiukun.zhou’s picture

Status: Needs work » Needs review
valthebald’s picture

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

xiukun.zhou’s picture

Status: Needs work » Active

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

xiukun.zhou’s picture

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

xiukun.zhou’s picture

Status: Active » Fixed

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

ludar’s picture

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

ckosloff’s picture

Issue summary: View changes

The latest recommended version solves all these issues.
Thank you.

stephanebourget’s picture

Hello, I applie the pacth #3 pacth, it solves a lot of bugs but my slidshow movement dont work, I have one fix slide only. Before my 5 slides are moving...Some one can help me ? Thanks

Michelle’s picture

Issue tags: -deprecated, -preg_replace(), -/e, -modifier, -use, -preg_replace_callback() +preg_replace, +PHP 5.4

Tagging this with the master tag for PHP 5.4 upgrade issues. (And cleaning up the unneeded tags while I'm at it.)

Michelle’s picture

If you are looking for a D6 fix, see #2512896: PHP 5.4+ compatibility which has this fix plus another one as well.

shaktik’s picture

Patch from #3 working fine.

Thank you!

enjayLema’s picture

please none of these is working for me what else can i do i need help asap!!!

Michelle’s picture

@enjayLema - This has already been committed so there is nothing you need to do except make sure you are on the latest version (or possibly the dev if there hasn't been a release since it was committed.)