I'm getting error with Symfony 1.4 Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /vagrant/lib/util/sfToolkit.class.php on line 365
The function concerned is below:
public static function pregtr($search, $replacePairs)
{
if(strpos(implode(', ', $replacePairs),'e') > 0)
print_r($replacePairs);
return preg_replace(array_keys($replacePairs),array_values($replacePairs), $search);
}
The values concerned is:
Array
(
[#/(.?)#e] => '::'.strtoupper('\1')
[/(^|_|-)+(.)/e] => strtoupper('\2')
)
How can I change this to what is equivalent using preg_replace_callback?
You can try to use the sf 1.5. version maintained by guys from L'Express: https://github.com/LExpress/symfony1 (they have fixed the problem)
If their changes are too much you can check how they managed to solve the 'e modifier' problem and copy their solution. Searching the code for use of pregtr it looks that there are only three places where the e modifier is used (in lib/util/sfInflector.class.php and in filter form classes in the Doctrine and Proper plugins). It's not that difficult to fix the code by yourself in those places.
Related
I've got some code that uses create_function, which is now deprecated. The comments for create_function say * #deprecated 7.2 Use anonymous functions instead.
This is the function itself: create_function ('$matches', 'return strtoupper("\0");')
And this is the context:
$match[1] = preg_replace_callback('/(?<=^|[\x09\x20\x2D])./',
create_function ('$matches', 'return strtoupper("\0");'), strtolower(trim($match[1])));
My code isn't running because it's been deprecated, so I want to turn it into an anonymous function instead. I'm not entirely sure what this bit of code does, so I don't really have a reliable way of testing it, but I THINK that create_function block can be replaced with
function($matches) {
return strtoupper($matches);
}
Would that work? Does that do the same thing that the create_function function does? I'm not sure what "\0" does in that context, so I'm hoping I can get some advice.
I found a similar question another place and tried the answer there. Turns out it's equivalent to this function:
function($m) {
return strtoupper($m[0]);
}
Found it here: Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback
thanks to #Philipp
I am currently re-programming a framework in php and I upgraded our development server to php 5.5.3. When I fire up the webbrowser, it returns the following error:
[19-Oct-2013 16:54:05 Europe/Amsterdam] PHP Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /Applications/MAMP/htdocs/fw/lib/lang.php on line 57
And line 57 is;
$response = preg_replace('/\{'.$find.'(:(.*))?\}/Ue', 'str_replace("{value}", "\\2", $replace)', $response);
I am really horrible at reading these php documentation, I am a beginner and simply changing preg_replace() by preg_replace_callback() is too good to be true. A co-worker told me it had to be something like $value[1] but that didn't work eather.
Is there a simple solution, am I overlooking something?
Here is the page about modifiers, giving you more detail about why it is deprecated, and what that means exactly.
Basically the reason is that the /e modifier causes a string to be evaluated as PHP code, as if eval was called. Using preg_replace_callback instead, which allows you to pass it an actual PHP function is indeed the way to go.
If you replace the string-code (second parameter) by an anonymous function, your code should then look something like this:
$response = preg_replace_callback(
'/\{'.$find.'(:(.*))?\}/U',
function($m) use ($replace) {
return str_replace($m, "\\2", $replace);
} ,
$response);
The keyword use makes sure that the anonymous function can use the $replace variable which should be defined in the calling scope. See this discussion.
I am using SolrPhpClient with Drupal and i want to use drupal as higher-layer user-interface to be able to query and retrieve search results from "apache solr"
I tried to use this example here (http://code.google.com/p/solr-php-client/wiki/ExampleUsage) for testing if drupal works with SolrPhpClient, but i am getting two errors which are presented below
1) Deprecated function: Function split() is deprecated in ApacheSolr_Response->_construct() (line 117 of /var/www/drupal/sites/all/modules/apachesolr/SolrPhpClient/Apache/Solr/Response.php).
2) Warning: htmlspecialchars() expects parameter 1 to be string, array given in eval() (line 80 of /var/www/drupal/modules/php/php.module(75) : eval()'d code).
Does anyone in reddit use SolrPhpClient before ? I have never used PHP so had a difficult time understanding it ?
Any kind of help will be appreciated
Many Thanks
split function is deprecated in PHP 5.3.0. So use explode function instead of split.
http://patelmilap.wordpress.com/2011/09/07/list-of-deprecated-functions-php/
And please tell me what are you passing in htmlspecialchars() function ?
It is used to Convert special characters to HTML entities.
http://php.net/manual/en/function.htmlspecialchars.php
$stringText = "[TEST-1] test task 1 Created: 06/Apr/11 Updated: 06/Apr/11";
$splitArray = split(" ",$stringText);
Deprecated: Function split() is deprecated in C:\wamp\www\RSS.php on line 27
Why this error happen ?
http://php.net/manual/en/function.split.php
From the manual
Warning This function has been
DEPRECATED as of PHP 5.3.0. Relying on
this feature is highly discouraged
Note:
As of PHP 5.3.0, the regex extension
is deprecated in favor of the PCRE
extension. Calling this function will
issue an E_DEPRECATED notice. See the
list of differences for help on
converting to PCRE.
I guess you're supposed to use the alternative preg_split(). Or if you're not using a regex, just use explode
split has been replaced with explode, see http://php.net/explode for more information. Works the same as split, but split is 'deprecated' basically means that is a old function that shouldn't be used anymore, and is not likely to be in later versions of php.
Use following explode function:
$command = explode(" ", $tag[1]);
This is the standard solution for this case.
Its Perfectly working.
Ahh, the docs says about it. And the docs also say which functions should be used instead of this:
preg_split
explode
str_split
Because the function has been deprecated? You can customize the error_reporting level to not log / display the depreciated errors. But it would be more prudent to just correct the issue (IE use explode instead for the simple split you are doing above.)
You can use this custom function for old codes:
if (!function_exists('split')) {
function split($pattern, $subject, $limit=-1, $flags=0){
return preg_split($pattern, $subject, $limit, $flags);
}
}
I'm new in this site. I want to ask about PHP programming. How do we can handle deprecated function in PHP. I want to redirect it to my new function. As we know, ereg function has been deprecated in PHP 5.3.0 and recommended to preg_match (posix to PCRE). But, when we wrote a lot of code with ereg function, do we have to change it manually? I want a solution like this.
function ereg($pattern, $string, &$array) { return preg_match('#'.$pattern.'#', $string, $array); }
The main problem is not the ereg function, but solution of handling deprecated function.
I've been searching in Google. Someone suggest to use override_function (using APD extension). But, this extension is hard to find (I need precompiled extension build for windows). Anyone can help me?
I'm sorry for my bad English. I hope you can understand.
The reason they tell you it is deprecated, and they don't remove it completely, is to give you time to update your code.
If you don't want to update your code, you can always just not upgrade your install of PHP. Or you can wait until a release of PHP is out were ereg() is removed completely, and use your above solution.
Other possible solutions include doing a search/replace for all ereg calls, and replacing it my_ereg, which could be the function you defined above.
Also:
if(!function_exists("ereg")){ .... }
Define the function inside of the if statement that checks if the function already exists. This will make the transition smoother.
But all in all, the purpose of deprecation is to give developers time to update their code and stop using all of the deprecated functions before they remove it completely from the code base.
I believe some call it 'Maintenance'.
You could always use the function_exists function.
if(!function_exists('ereg'))
{
function ereg($pattern, $string, &$array)
{
return preg_match('#'.$pattern.'#', $string, $array);
}
}
Using this method would allow it to work in all version as if it is deprecated but still able to be used it will use the function but once it has been removed from php it will be able to use your user defined function.