Skip to content

Commit 448e486

Browse files
authored
Merge pull request #163 from e1himself/fix/php-7.2-deprecation-warnings
Fix/php 7.2 deprecation warnings
2 parents ee35ff0 + 34790ba commit 448e486

12 files changed

+45
-44
lines changed

lib/cache/sfMemcacheCache.class.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,12 @@ public function removePattern($pattern)
223223
public function getMany($keys)
224224
{
225225
$values = array();
226-
foreach ($this->memcache->get(array_map(create_function('$k', 'return "'.$this->getOption('prefix').'".$k;'), $keys)) as $key => $value)
226+
$prefix = $this->getOption('prefix');
227+
$prefixed_keys = array_map(function($k) use ($prefix) { return $prefix . $k; }, $keys);
228+
229+
foreach ($this->memcache->get($prefixed_keys) as $key => $value)
227230
{
228-
$values[str_replace($this->getOption('prefix'), '', $key)] = $value;
231+
$values[str_replace($prefix, '', $key)] = $value;
229232
}
230233

231234
return $values;

lib/command/sfCommandApplication.class.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,12 @@ protected function fixCgi()
605605
}
606606

607607
// close the streams on script termination
608-
register_shutdown_function(create_function('', 'fclose(STDIN); fclose(STDOUT); fclose(STDERR); return true;'));
608+
register_shutdown_function(function() {
609+
fclose(STDIN);
610+
fclose(STDOUT);
611+
fclose(STDERR);
612+
return true;
613+
});
609614
}
610615

611616
/**

lib/config/sfConfigHandler.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static public function replaceConstants($value)
7777
{
7878
if (is_array($value))
7979
{
80-
array_walk_recursive($value, create_function('&$value', '$value = sfToolkit::replaceConstants($value);'));
80+
array_walk_recursive($value, function(& $value) { $value = sfToolkit::replaceConstants($value); });
8181
}
8282
else
8383
{
@@ -98,7 +98,7 @@ static public function replacePath($path)
9898
{
9999
if (is_array($path))
100100
{
101-
array_walk_recursive($path, create_function('&$path', '$path = sfConfigHandler::replacePath($path);'));
101+
array_walk_recursive($path, function(&$path) { $path = sfConfigHandler::replacePath($path); });
102102
}
103103
else
104104
{

lib/helper/TextHelper.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -278,33 +278,26 @@ function _auto_link_urls($text, $href_options = array(), $truncate = false, $tru
278278
{
279279
$href_options = _tag_options($href_options);
280280

281-
$callback_function = '
282-
if (preg_match("/<a\s/i", $matches[1]))
283-
{
284-
return $matches[0];
285-
}
286-
';
281+
$callback_function = function($matches) use ($href_options, $truncate, $truncate_len, $pad) {
282+
if (preg_match("/<a\s/i", $matches[1]))
283+
{
284+
return $matches[0];
285+
}
287286

288-
if ($truncate)
289-
{
290-
$callback_function .= '
291-
else if (strlen($matches[2].$matches[3]) > '.$truncate_len.')
287+
$text = $matches[2] . $matches[3];
288+
$href = ($matches[2] == "www." ? "http://www." : $matches[2]) . $matches[3];
289+
290+
if ($truncate && strlen($text) > $truncate_len)
292291
{
293-
return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.substr($matches[2].$matches[3], 0, '.$truncate_len.').\''.$pad.'</a>\'.$matches[4];
292+
$text = substr($text, 0, $truncate_len).$pad;
294293
}
295-
';
296-
}
297294

298-
$callback_function .= '
299-
else
300-
{
301-
return $matches[1].\'<a href="\'.($matches[2] == "www." ? "http://www." : $matches[2]).$matches[3].\'"'.$href_options.'>\'.$matches[2].$matches[3].\'</a>\'.$matches[4];
302-
}
303-
';
295+
return sprintf('%s<a href="%s"%s>%s</a>%s', $matches[1], $href, $href_options, $text, $matches[4]);
296+
};
304297

305298
return preg_replace_callback(
306299
SF_AUTO_LINK_RE,
307-
create_function('$matches', $callback_function),
300+
$callback_function,
308301
$text
309302
);
310303
}

lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineDeleteModelFilesTask.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function execute($arguments = array(), $options = array())
7676
{
7777
if (!$options['no-confirmation'] && !$this->askConfirmation(array_merge(
7878
array('The following '.$modelName.' files will be deleted:', ''),
79-
array_map(create_function('$v', 'return \' - \'.sfDebug::shortenFilePath($v);'), $files),
79+
array_map(function($v) { return ' - '.sfDebug::shortenFilePath($v); }, $files),
8080
array('', 'Continue? (y/N)')
8181
), 'QUESTION_LARGE', false))
8282
{
@@ -100,10 +100,10 @@ protected function execute($arguments = array(), $options = array())
100100

101101
/**
102102
* Converts an array of values to a regular expression pattern fragment.
103-
*
103+
*
104104
* @param array $values An array of values for the pattern
105105
* @param string $delimiter The regular expression delimiter
106-
*
106+
*
107107
* @return string A regular expression fragment
108108
*/
109109
protected function valuesToRegex($values, $delimiter = '/')

lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineDropDbTask.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected function execute($arguments = array(), $options = array())
7373
&&
7474
!$this->askConfirmation(array_merge(
7575
array(sprintf('This command will remove all data in the following "%s" connection(s):', $environment), ''),
76-
array_map(create_function('$v', 'return \' - \'.$v;'), array_keys($databases)),
76+
array_map(function($v) { return ' - '.$v; }, array_keys($databases)),
7777
array('', 'Are you sure you want to proceed? (y/N)')
7878
), 'QUESTION_LARGE', false)
7979
)

lib/plugins/sfDoctrinePlugin/lib/task/sfDoctrineMigrateTask.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function execute($arguments = array(), $options = array())
137137
{
138138
$this->logBlock(array_merge(
139139
array('The following errors occurred:', ''),
140-
array_map(create_function('$e', 'return \' - \'.$e->getMessage();'), $migration->getErrors())
140+
array_map(function($e) { return ' - '.$e->getMessage(); }, $migration->getErrors())
141141
), 'ERROR_LARGE');
142142
}
143143

lib/routing/sfRoute.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ protected function initializeOptions()
696696
'extra_parameters_as_query_string' => true,
697697
), $this->getDefaultOptions(), $this->options);
698698

699-
$preg_quote_hash = create_function('$a', 'return preg_quote($a, \'#\');');
699+
$preg_quote_hash = function($a) { return preg_quote($a, '#'); };
700700

701701
// compute some regexes
702702
$this->options['variable_prefix_regex'] = '(?:'.implode('|', array_map($preg_quote_hash, $this->options['variable_prefixes'])).')';
@@ -706,7 +706,7 @@ protected function initializeOptions()
706706
$this->options['segment_separators_regex'] = '(?:'.implode('|', array_map($preg_quote_hash, $this->options['segment_separators'])).')';
707707

708708
// as of PHP 5.3.0, preg_quote automatically quotes dashes "-" (see http://bugs.php.net/bug.php?id=47229)
709-
$preg_quote_hash_53 = create_function('$a', 'return str_replace(\'-\', \'\-\', preg_quote($a, \'#\'));');
709+
$preg_quote_hash_53 = function($a) { return str_replace('-', '\-', preg_quote($a, '#')); };
710710
$this->options['variable_content_regex'] = '[^'.implode('',
711711
array_map(version_compare(PHP_VERSION, '5.3.0RC4', '>=') ? $preg_quote_hash : $preg_quote_hash_53, $this->options['segment_separators'])
712712
).']+';

lib/task/project/sfProjectPermissionsTask.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
* This file is part of the symfony package.
55
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6-
*
6+
*
77
* For the full copyright and license information, please view the LICENSE
88
* file that was distributed with this source code.
99
*/
@@ -72,18 +72,18 @@ protected function execute($arguments = array(), $options = array())
7272
{
7373
$this->logBlock(array_merge(
7474
array('Permissions on the following file(s) could not be fixed:', ''),
75-
array_map(create_function('$f', 'return \' - \'.sfDebug::shortenFilePath($f);'), $this->failed)
75+
array_map(function($f) { return ' - '.sfDebug::shortenFilePath($f); }, $this->failed)
7676
), 'ERROR_LARGE');
7777
}
7878
}
7979

8080
/**
8181
* Chmod and capture any failures.
82-
*
82+
*
8383
* @param string $file
8484
* @param integer $mode
8585
* @param integer $umask
86-
*
86+
*
8787
* @see sfFilesystem
8888
*/
8989
protected function chmod($file, $mode, $umask = 0000)
@@ -109,7 +109,7 @@ protected function chmod($file, $mode, $umask = 0000)
109109

110110
/**
111111
* Captures those chmod commands that fail.
112-
*
112+
*
113113
* @see http://www.php.net/set_error_handler
114114
*/
115115
public function handleError($no, $string, $file, $line, $context)

lib/util/sfBrowserBase.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ protected function parseArgumentAsArray($name, $value, &$vars)
927927
if (false !== $pos = strpos($name, '['))
928928
{
929929
$var = &$vars;
930-
$tmps = array_filter(preg_split('/(\[ | \[\] | \])/x', $name), create_function('$s', 'return $s !== "";'));
930+
$tmps = array_filter(preg_split('/(\[ | \[\] | \])/x', $name), function($s) { return $s !== ''; });
931931
foreach ($tmps as $tmp)
932932
{
933933
$var = &$var[$tmp];

0 commit comments

Comments
 (0)