Symfony 1.4 deprecated function in php

后端 未结 4 2003
感动是毒
感动是毒 2021-01-01 03:54

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

相关标签:
4条回答
  • 2021-01-01 04:29

    You can unset the E_DEPRECATED flag in every application settings.yml :

    dev:
      .settings:
         error_reporting:  <?php echo ((E_ALL | E_STRICT) ^ E_DEPRECATED)."\n" ?>
    
    0 讨论(0)
  • 2021-01-01 04:30

    Found this:

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

    Tested, all changes look good

    0 讨论(0)
  • 2021-01-01 04:34

    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(' ' => ''));
      }
    
    0 讨论(0)
  • as this function is called in several files in sf 1.4, here are all changes that i made in my projects (based on different sources, including sf 1.4 forks):

    lib/vendor/symfony/lib/command/sfCommandManager.class.php
        @@ -108,7 +108,9 @@ class sfCommandManager
             else if (!is_array($arguments))
             {
               // hack to split arguments with spaces : --test="with some spaces"
        -      $arguments = preg_replace('/(\'|")(.+?)\\1/e', "str_replace(' ', '=PLACEHOLDER=', '\\2')", $arguments);
        +      $arguments = preg_replace_callback('/(\'|")(.+?)\\1/', function ($match) {
        +        return str_replace(' ', '=PLACEHOLDER=', $match[2]);
        +      }, $arguments);
               $arguments = preg_split('/\s+/', $arguments);
               $arguments = str_replace('=PLACEHOLDER=', ' ', $arguments);
             }
    
    lib/vendor/symfony/lib/form/addon/sfFormObject.class.php
    @@ -278,6 +278,6 @@ abstract class sfFormObject extends BaseForm
    
       protected function camelize($text)
       {
    -    return preg_replace(array('#/(.?)#e', '/(^|_|-)+(.)/e'), array("'::'.strtoupper('\\1')", "strtoupper('\\2')"), $text);
    +    return strtr(ucwords(strtr($text, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
       }
    
    lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormFilterDoctrine.class.php
    @@ -323,7 +323,7 @@ abstract class sfFormFilterDoctrine extends sfFormFilter
    
       protected function camelize($text)
       {
    -    return sfToolkit::pregtr($text, array('#/(.?)#e' => "'::'.strtoupper('\\1')", '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
    +    return strtr(ucwords(strtr($text, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
       }
    
    lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/form/sfFormFilterPropel.class.php
    @@ -263,6 +263,6 @@ abstract class sfFormFilterPropel extends sfFormFilter
    
       protected function camelize($text)
       {
    -    return sfToolkit::pregtr($text, array('#/(.?)#e' => "'::'.strtoupper('\\1')", '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
    +    return strtr(ucwords(strtr($text, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
       }
    
    
    lib/vendor/symfony/lib/response/sfWebResponse.class.php
    @@ -406,7 +406,7 @@ class sfWebResponse extends sfResponse
    
       protected function normalizeHeaderName($name)
       {
    -    return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));
    +    return strtr(ucwords(strtr(strtolower($name), array('_' => ' ', '-' => ' '))), array(' ' => '-'));
       }
    
    
    lib/vendor/symfony/lib/util/sfInflector.class.php
    @@ -27,11 +27,7 @@ class sfInflector
    
       public static function camelize($lower_case_and_underscored_word)
       {
    -    $tmp = $lower_case_and_underscored_word;
    -    $tmp = sfToolkit::pregtr($tmp, array('#/(.?)#e'    => "'::'.strtoupper('\\1')",
    -                                         '/(^|_|-)+(.)/e' => "strtoupper('\\2')"));
    -
    -    return $tmp;
    +    return strtr(ucwords(strtr($lower_case_and_underscored_word, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
       }
    

    beside, here is the fix for the E_NOTICE lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Query/Abstract.php:

    lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Query/Abstract.php
    @@ -1149,7 +1149,16 @@ abstract class Doctrine_Query_Abstract
             $copy->free();
    
             if ($componentsBefore !== $componentsAfter) {
    -            return array_diff($componentsAfter, $componentsBefore);
    +            $diff = array();
    +
    +                       foreach($componentsAfter as $key => $val) {
    +                               if(!isset($componentsBefore[$key])) {
    +                                       $diff[$key] = $val;
    +                               } elseif(is_array($componentsBefore[$key]) && !is_array($val)) {
    +                                       $diff[$key] = $val;
    +                               }
    +                       }
    +                       return $diff;
             } else {
                 return $componentsAfter;
             }
    
    0 讨论(0)
提交回复
热议问题