title: PHP change create_function to anonymous function
body: <p>I have inherited some old code and need to convert the create_function to an anonymous function.  I have done that but since I cannot see the code in the anonymous function I do not know if it equals the code in the former create_function.</p>
  <p>Here is the code and my question is: is 'my translation' equal to the 'original code'?</p>
  <pre><code>public static function makePhpVdtorFromRegex($regex, $match = TRUE)
  {
      //original code
      $s = 'return '.($match?'':'0 == ').'preg_match(\'/'.addslashes($regex).'/\',$v);';
      return create_function('$v', $s);
  
      // my translation
      return function($v) use ($regex, $match) {
          return ($match?'':'0 == ').preg_match('/'.addslashes($regex).'/',$v);
      };
  }
  </code></pre>
  <p>I believe makePhpVdtorFromRegex stands for 'Make PHP Validator From Regex'. The problem in validating this is I am not sure where the actual validator is used as this anonymous function is stored in an array which is used to validate input at some later time doing form input validation.</p>
  <p>Because $regex and $match only exist within makePhpVdtorFromRegex() they will not be available when the validator is ultimately run, right? So I suspect my translation is not going to work?</p>