Skip to content

Commit

Permalink
hack: these are alreaty defined on wpcom
Browse files Browse the repository at this point in the history
  • Loading branch information
yoavf committed Apr 13, 2016
1 parent cf79051 commit 4852995
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions gp-includes/deprecated.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
*
* @param mixed $value
*/
function returner( $value ) {
return create_function( '', 'return '.var_export( $value, true ).';');
if ( ! function_exists( 'returner' ) ) {
function returner( $value ) {
return create_function( '', 'return ' . var_export( $value, true ) . ';' );
}
}

/**
* Creates a function, which prints $value
*
* @param mixed $value
*/
function echoer( $value ) {
return create_function( '', 'echo '.var_export( $value, true ).';');
if ( ! function_exists( 'echoer' ) ) {
function echoer( $value ) {
return create_function( '', 'echo ' . var_export( $value, true ) . ';' );
}
}

/**
Expand All @@ -32,14 +36,17 @@ function echoer( $value ) {
* @param string $expression String with an expression -- the result of the function
* @param array $locals The items in this array will be extracted in the function as local variables.
*/
function lambda( $args, $expression, $locals = array() ) {
$export_call = $locals? 'extract('.var_export( $locals, true ).', EXTR_PREFIX_SAME, "ext");' : '';
return create_function( $args, $export_call.' return ('.rtrim( $expression, '; ' ).');' );
if ( ! function_exists( 'lambda' ) ) {
function lambda( $args, $expression, $locals = array() ) {
$export_call = $locals ? 'extract(' . var_export( $locals, true ) . ', EXTR_PREFIX_SAME, "ext");' : '';

return create_function( $args, $export_call . ' return (' . rtrim( $expression, '; ' ) . ');' );
}
}

/**
* Returns a function, which returns the string "odd" or the string "even" alternatively.
*/
function gp_parity_factory() {
return create_function( '', 'static $parity = "even"; if ($parity == "even") $parity = "odd"; else $parity = "even"; return $parity;');
}
}

0 comments on commit 4852995

Please sign in to comment.