Browse files

Merge pull request #123 from caseysoftware/preg-refactor-e

Removed the preg_replace /e modifier in favor of using create_function
  • Loading branch information...
2 parents 992942f + c55c8c1 commit f1e4ff854e93cbcb754091f0f61b8697181e5afb @caseysoftware caseysoftware committed Jun 12, 2013
Showing with 11 additions and 4 deletions.
  1. +11 −4 Services/Twilio/Resource.php
View
15 Services/Twilio/Resource.php
@@ -71,9 +71,12 @@ public function getResourceName($camelized = false)
public static function decamelize($word)
{
- return preg_replace(
- '/(^|[a-z])([A-Z])/e',
- 'strtolower(strlen("\\1") ? "\\1_\\2" : "\\2")',
+ $callback = create_function('$matches',
+ 'return strtolower(strlen("$matches[1]") ? "$matches[1]_$matches[2]" : "$matches[2]");');
+
+ return preg_replace_callback(
+ '/(^|[a-z])([A-Z])/',
+ $callback,
$word
);
}
@@ -87,7 +90,11 @@ public static function decamelize($word)
* @return string
*/
public static function camelize($word) {
- return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word);
+ $callback = create_function('$matches', 'return strtoupper("$matches[2]");');
+
+ return preg_replace_callback('/(^|_)([a-z])/',
+ $callback,
+ $word);
}
/**

0 comments on commit f1e4ff8

Please sign in to comment.