Another closure test comes in.
The build was successful.
Details
The build was successful.
Details
This commit is contained in:
parent
31f48b234b
commit
5cc803d07c
|
@ -0,0 +1,36 @@
|
|||
class Operations {
|
||||
|
||||
public callback ops(int $x, int $y, string $op){
|
||||
switch($op) {
|
||||
case 'ADD':
|
||||
return int() using ($x, $y) {
|
||||
return $x + $y;
|
||||
};
|
||||
break;
|
||||
case 'SUB':
|
||||
return int() using ($x, $y) {
|
||||
return $x - $y;
|
||||
};
|
||||
break;
|
||||
default:
|
||||
return string() {
|
||||
return 'Operation is not supported by class.';
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Program {
|
||||
|
||||
void main() {
|
||||
callback $fn;
|
||||
object $op = new Operations();
|
||||
$fn = $op->ops(6, 7, 'ADD');
|
||||
print($fn() + "\n");
|
||||
$fn = $op->ops(6, 2, 'SUB');
|
||||
print($fn() + "\n");
|
||||
$fn = $op->ops(6, 7, 'MUL');
|
||||
print($fn() + "\n");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
13
|
||||
4
|
||||
Operation is not supported by class.
|
Loading…
Reference in New Issue