[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> lambda.php (source)

   1  <?php
   2  /**
   3   * create_function wrappers
   4   */
   5  
   6  /**
   7   * Creates a function, which returns $value
   8   *
   9   * @param mixed $value
  10   */
  11  function returner( $value ) {
  12      return create_function( '', 'return '.var_export( $value, true ).';');
  13  }
  14  
  15  /**
  16   * Creates a function, which prints $value
  17   *
  18   * @param mixed $value
  19   */
  20  function echoer( $value ) {
  21      return create_function( '', 'echo '.var_export( $value, true ).';');
  22  }
  23  
  24  /**
  25   * Creates a function, which accepts $args and returns the expression in $expression.
  26   *
  27   * Items from the optional array $locals can be used as local variables in the function.
  28   * In case of collision a formal arguments and a key in $locals, the latter will be prefixed
  29   * with ext_
  30   *
  31   * @param string $args String with the function arguments
  32   * @param string $expression String with an expression -- the result of the function
  33   * @param array $locals The items in this array will be extracted in the function as local variables.
  34   */
  35  function lambda( $args, $expression, $locals = array() ) {
  36      $export_call = $locals? 'extract('.var_export( $locals, true ).', EXTR_PREFIX_SAME, "ext");' : '';
  37      return create_function( $args, $export_call.' return ('.rtrim( $expression, '; ' ).');' );
  38  }


Generated: Tue May 21 03:59:56 2013 Hosted by follow the white rabbit.