Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 1.4 deprecated function in php

Tags:

symfony-1.4

Anyone know what is this error? I need help with this Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in C:\xampp\htdocs\sfprojects\jobeet\lib\vendor\symfony\lib\response\sfWebResponse.class.php on line 409. I'm using xampp 1.8.3 and symfony 1.4. I couldn't get to step forward because of this a weeke a go :'(. Any help will be appreciated. Thank you.

like image 760
Hisam Hershy Avatar asked Feb 15 '23 03:02

Hisam Hershy


2 Answers

In myproject/lib/vendor/symfony/lib/response/sfWebResponse.class.php on line 409

  protected function normalizeHeaderName($name)
  {
    // return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));    

    return preg_replace_callback(
                  '/\-(.)/', 
                  function ($matches) {
                    return '-'.strtoupper($matches[1]);
                  }, 
                  strtr(ucfirst(strtolower($name)), '_', '-')
        );
  }

FIX for pregtr method in /lib/vendor/symfony/lib/util/sfToolkit.class.php on line 360

public static function pregtr($search, $replacePairs){
  // return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search);
  foreach($replacePairs as $pattern => $replacement)
  {
    if (preg_match('/(.*)e$/', $pattern, $matches))
    {
      $pattern = $matches[1];
      $search = preg_replace_callback($pattern, function ($matches) use ($replacement) {
        preg_match("/('::'\.)?([a-z]*)\('\\\\([0-9]{1})'\)/", $replacement, $match);
        return ($match[1]==''?'':'::').call_user_func($match[2], $matches[$match[3]]);
      }, $search);
    }
    else
    {
      $search = preg_replace($pattern, $replacement, $search);
    }
  }
  return $search;
}

I've combined two answers from duplicate thread Symfony 1.4 using deprecated functions in php 5.5 answered by mika and xtech (up-vote them please)

It also affects /lib/form/addon/sfFormObject.class.php on line 281

  protected function camelize($text)
  {
    //return preg_replace(array('#/(.?)#e', '/(^|_|-)+(.)/e'), array("'::'.strtoupper('\\1')", "strtoupper('\\2')"), $text); //ORIGINAL
    return strtr(ucwords(strtr($text, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
  }
like image 172
Radamanf Avatar answered May 01 '23 19:05

Radamanf


Found this:

http://blog.jakoubek.cz/symfony-1-4-deprecated-e-modifier

Tested, all changes look good

like image 32
ImLeo Avatar answered May 01 '23 21:05

ImLeo