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.
Asked
Active
Viewed 6,638 times
4

Hisam Hershy
- 91
- 1
- 3
- 8
-
Please open said file and look up line 409. If you don't know what it means, post it here. – Phil Jan 13 '14 at 13:08
-
`return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));` this is at line 409. – Hisam Hershy Jan 13 '14 at 14:02
-
Ok, the problem is the `e` in `'/\-(.)/e'`. You can try simply removing it, but that might break functionality. If you want to fix it properly, read this http://de.php.net/manual/en/reference.pcre.pattern.modifiers.php (PREG_REPLACE_EVAL). Other than that, your only options are turning off warnings, as this is apparently still working properly, or just downgrade PHP to 5.4, which still supports this feature. – Phil Jan 13 '14 at 22:26
-
Thank you @MrTweek. I'll do it. – Hisam Hershy Jan 14 '14 at 05:58
-
It says `Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead`. can you translate it that line 409 for for me with the valid function it says (`preg_replace_callback()`). Thank you – Hisam Hershy Jan 14 '14 at 06:23
-
Hello, symfony 1.4 isn't compatible with PHP 5.5. That's why you get this error. What I can suggest, is to use test our fork of symfony 1.4 that is compatible with PHP 5.5 it also add the DIC. Have a look: https://github.com/LExpress/symfony1 – j0k Jan 15 '14 at 09:14
4 Answers
6
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
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;
}

Anybug
- 616
- 7
- 5
-1
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" ?>

Tamer Ibrahim
- 25
- 3
-
1This is a bad solution as I've already down voted in duplicate thread, as it only hides the problem and not fixes it. (C.O.) Hopefully Symfony 1.4.21 will fix those issues. – Radamanf Aug 06 '14 at 09:34