-
Notifications
You must be signed in to change notification settings - Fork 6
/
utility.php
56 lines (47 loc) · 1.06 KB
/
utility.php
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
55
56
<?php
use PhpParser\PrettyPrinter;
use PhpParser\Node;
$log = fopen('php://stderr','a');
$prettyPrinter = new PrettyPrinter\Standard;
function pp($msg) {
global $log;
if (gettype($msg) == 'array' || gettype($msg) == 'object') {
fwrite($log, var_dump($msg).PHP_EOL);
}
else {
fwrite($log, $msg.PHP_EOL);
}
}
function deep_copy_arr($arr) {
$newarray = [];
foreach ($arr as $k=>$v) {
$newarray[$k] = clone $v;
}
return $newarray;
}
function soft_copy_arr($arr) {
$newarray = [];
foreach ($arr as $k=>$v) {
$newarray[$k] = &$v;
}
return $newarray;
}
function deep_copy_2d_arr($arr) {
$new = [];
foreach ($arr as $k=>$v) {
$newi = [];
foreach ($v as $vk=>$vv) {
$newi[$vk] = clone $vv;
}
$new[$k] = $newi;
}
return $new;
}
function get_stmt_str($stmt) {
global $prettyPrinter;
return $prettyPrinter->prettyPrint([$stmt]);
}
function get_stmts_str($stmts) {
global $prettyPrinter;
return $prettyPrinter->prettyPrint($stmts);
}