[ Index ]

PHP Cross Reference of GlotPress

title

Body

[close]

/gp-includes/ -> deprecated.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  }
  39  
  40  /**
  41   * Returns a function, which returns the string "odd" or the string "even" alternatively.
  42   */
  43  function gp_parity_factory() {
  44      return create_function( '', 'static $parity = "even"; if ($parity == "even") $parity = "odd"; else $parity = "even"; return $parity;');
  45  }


Generated: Wed Oct 4 01:02:16 2017 Cross-referenced by PHPXref 0.7.1