As you might know Symfony 1.4.x has ended its LTS in last November 2012, at that time PHP 5.5 was not released yet. That 5.5 version came in June 2013 and if you want to upgrade to that version you need to know about Symfony 1.4.x is not 100% compatible with PHP 5.5.
If you upgrade to PHP 5.5 you will start seeing a couple of warnings in your Symfony 1.4 application:
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in lib/vendor/symfony/…
In this post I will show you a patch to fix these warnings and make Symfony works over PHP 5.5.
In lib/vendor/symfony/lib/command/sfCommandManager.class.php:
1 2 3 4 5 6 7 8 9 10 11 | @@ -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($matches) { + return str_replace(' ', '=PLACEHOLDER=', $matches[2]); + }, $arguments); $arguments = preg_split('/\s+/', $arguments); $arguments = str_replace('=PLACEHOLDER=', ' ', $arguments); } |
In lib/vendor/symfony/lib/form/addon/sfFormObject.class.php:
1 2 3 4 5 6 7 8 | @@ -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 sfToolkit::camelize($text); } } |
In lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/form/sfFormFilterDoctrine.class.php:
1 2 3 4 5 6 7 | @@ -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 sfToolkit::camelize($text); } |
In lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/form/sfFormFilterPropel.class.php:
1 2 3 4 5 6 7 8 | @@ -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 sfToolkit::camelize($text); } } |
In lib/vendor/symfony/lib/response/sfWebResponse.class.php:
1 2 3 4 5 6 7 | @@ -406,7 +406,7 @@ class sfWebResponse extends sfResponse */ 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)), '_', '-')); } |
In lib/vendor/symfony/lib/util/sfInflector.class.php:
1 2 3 4 5 6 7 8 9 10 | @@ -28,10 +28,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 sfToolkit::camelize($tmp);; } |
EDIT: I’ve added a improved camelize function that the original.
In lib/vendor/symfony/lib/util/sfToolkit.class.php:
1 2 3 4 5 6 7 8 9 10 |
This patch was tested in Symfony 1.4.20 and it works properly.
EDIT: Do NOT use Symfony 1.4.x for new projects. This patch works for existing legacy symfony1 applications, but Symfony2 is the way to go today.