-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_as_variable.php
More file actions
44 lines (33 loc) · 1.12 KB
/
function_as_variable.php
File metadata and controls
44 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/*
* Copyright (C) 2024-2026 Katarzyna Krasińska
* PHP.lab - https://github.com/katheroine/php.lab
* Licensed under GPL-3.0 - see LICENSE.md
*/
function someFunction(int $someArgument): int
{
$result = $someArgument * 2;
return $result;
}
$someFunctionVariable1 = 'someFunction';
$result = $someFunctionVariable1(3);
print("Some function result: {$result}\n");
$someFunctionVariable2 = someFunction(...);
$result = $someFunctionVariable2(3);
print("Some function result: {$result}\n");
$someFunctionVariable3 = 'someFunction'(...);
$result = $someFunctionVariable2(3);
print("Some function result: {$result}\n");
$someFunctionVariable4 = Closure::fromCallable('someFunction');
$result = $someFunctionVariable4(3);
print("Some function result: {$result}\n");
$otherFunctionVariable1 = function (int $someArgument): int
{
$result = $someArgument * 3;
return $result;
};
$result = $otherFunctionVariable1(3);
print("Other function result: {$result}\n");
$otherFunctionVariable2 = Closure::fromCallable($otherFunctionVariable1);
$result = $otherFunctionVariable2(3);
print("Other function result: {$result}\n");