Thursday, 19 May 2016

Deprecated: preg_replace()

Contoh 1 :

Dari lib/vendor/symfony/lib/controller/sfRouting.class.php (symfony 1.4)

....
$real_url = preg_replace('/\:([^\/]+)/e', 'urlencode($params["\\1"])', $url);
....

Menjadi :

private function callbackurl($matches) {
  urlencode($matches[1]);
}

....
$real_url = preg_replace_callback('/\:([^\/]+)/', array($this,'callbackurl'), $url);
....

Contoh 2 :


Dari lib/vendor/symfony/lib/response/sfWebResponse.class.php (symfony 1.4)

....
return preg_replace('/\-(.)/e', "'-'.strtoupper('\\1')", strtr(ucfirst(strtolower($name)), '_', '-'));
....

Menjadi  :

protected function callbacknormalizeHeaderName($matches) {
  return '-'.strtoupper($matches[1]);
}

.....
return preg_replace_callback('/\-(.)/', array($this,'callbacknormalizeHeaderName'), strtr(ucfirst(strtolower($name)), '_', '-'));
....
Contoh   :

Dari lib/vendor/symfony/lib/addon/propel/builder/SfMapBuilderBuilder.php (symfony 1.0)

.....
$script = preg_replace("/\\\$tMap\->addColumn\('([^']+)', '([^']+)', '([^']+)', CreoleTypes\:\:VARCHAR, (false|true)\)/e", '"\\\$tMap->addColumn(\'$1\', \'$2\', \'$3\', CreoleTypes::VARCHAR, $4, {$sizes[\'$2\']})"', $script);
....

Menjadi :

..

Referensi


  1. fixes #679 change using preg_replace e modifier to preg_replace_callb..., https://github.com/asmisha/SonataDoctrineORMAdminBundle/commit/9fd60a4641f6b8bfc2f89e29b8ab84c47aa62f7e

No comments:

Post a Comment