Skip to content

Instantly share code, notes, and snippets.

@maeharin
Last active December 11, 2015 05:39
Show Gist options
  • Save maeharin/4554124 to your computer and use it in GitHub Desktop.
Save maeharin/4554124 to your computer and use it in GitHub Desktop.
<?php
// ワンソース
function event() {
$args = func_get_args();
$name = array_shift($args);
$callable = array_pop($args);
$is_call = $callable();
if($is_call) {echo $name;}
}
$weather = 'sunny';
//$weather = 'rain';
event('今日は晴れています', function() use ($weather) {
return $weather === 'sunny';
});
event('今日は雨です', function() use ($weather) {
return $weather === 'rain';
});
<?php
function event() {
$args = func_get_args();
$name = array_shift($args);
$callable = array_pop($args);
$is_call = $callable();
if($is_call) {echo $name;}
}
require 'two_source02.php';
<?php
$weather = 'sunny';
//$weather = 'rain';
event('今日は晴れています', function() use ($weather) {
return $weather === 'sunny';
});
event('今日は雨です', function() use ($weather) {
return $weather === 'rain';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment