Symfony 1.4在PHP中弃用了函数

时间:2014-01-13 12:59:55

标签: symfony-1.4

任何人都知道这个错误是什么?我需要帮助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。我正在使用 xampp 1.8.3 symfony 1.4 。 我无法向前迈进,因为这个周末去了:'(。任何帮助都会受到赞赏。谢谢。

4 个答案:

答案 0 :(得分:4)

在第409行的myproject / lib / vendor / symfony / lib / response / sfWebResponse.class.php中

  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)), '_', '-')
        );
  }

第360行/lib/vendor/symfony/lib/util/sfToolkit.class.php中的pregtr方法的FIX

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;
}

我结合了Symfony 1.4 using deprecated functions in php 5.5mika回答的重复帖子xtech中的两个答案(请将其投票)

它也会影响第281行的/lib/form/addon/sfFormObject.class.php

  protected function camelize($text)
  {
    //return preg_replace(array('#/(.?)#e', '/(^|_|-)+(.)/e'), array("'::'.strtoupper('\\1')", "strtoupper('\\2')"), $text); //ORIGINAL
    return strtr(ucwords(strtr($text, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => ''));
  }

答案 1 :(得分:3)

发现这个:

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

经过测试,所有更改都很好看

答案 2 :(得分:0)

因为在sf 1.4中的几个文件中调用了这个函数,以下是我在项目中所做的所有更改(基于不同的源,包括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(' ' => ''));
   }

旁边,这里是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;
         }

答案 3 :(得分:-1)

您可以在每个应用程序settings.yml中取消设置E_DEPRECATED标志:

dev:
  .settings:
     error_reporting:  <?php echo ((E_ALL | E_STRICT) ^ E_DEPRECATED)."\n" ?>