-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlect2.php
More file actions
54 lines (45 loc) · 1020 Bytes
/
lect2.php
File metadata and controls
54 lines (45 loc) · 1020 Bytes
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
45
46
47
48
49
50
51
52
53
54
<?php
/**
* Created by PhpStorm.
* User: APG
* Date: 16.05.2020
* Time: 15:06
*/
# help function
function test($name, callable $callback)
{
echo 'invoke: ' . $callback($name) . PHP_EOL;
echo 'user_func: ' . call_user_func_array($callback, [$name]) . PHP_EOL;
}
class SayHello
{
public static function helloStatic($name = '')
{
return 'Say hello from static ' . $name . PHP_EOL;
}
public function hello($name = '')
{
return 'Say hello from pubf ' . $name . PHP_EOL;
}
}
/*
# string like
function simpleHello($name = '')
{
return 'Simple Hello to : ' . $name;
}
echo "<pre>";
test('World', 'simpleHello');
# anonym like
test('Anonym', function($name) {
return 'Hello to : ' . $name . PHP_EOL;
});
*/
echo "<pre>";
# object and array
$obj = new SayHello();
# 1 èìÿ è èìÿ êëàññà è èìÿ ñòàòè÷íîãî ïóáëè÷íîãî ìåòîäà
test('Static', [SayHello::class, 'helloStatic']);
#2 ñîçäàòü ýêçåìïëÿð êëàññà è ïåðåäàòü
test('NonStatic', [$obj, 'hello']);
echo "</pre>";