-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.php
91 lines (65 loc) · 1.46 KB
/
Functions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Pronode;
/**
* Returns $var type.
* If $var is an object, returns object class.
*
* @param mixed $var
* @return string
*/
function get_type($var) : string {
$type = gettype($var);
if ($type == 'object') {
return get_class($var);
}
return $type;
}
/**
* Checks whether variable is an array of numeric-indexes only.
*
* @param mixed $array
* @return boolean
*/
function is_iter($array) : bool {
if (!is_array($array)) return false;
if (array() === $array) return false;
foreach (array_keys($array) as $key) {
if (!is_numeric($key)) return false;
}
return true;
}
/**
* Checks whether variable is an array of string-indexes.
*
* @param mixed $array
* @return boolean
*/
function is_assoc($array) : bool {
if (!is_array($array)) return false;
if (array() === $array) return false;
return !is_iter($array);
}
/**
* Alias for var_dump
*
* @param mixed $var
*/
function v($var) : void {
var_dump($var);
}
/**
* Quick Benchmark to measure execution time of given function.
*
* usage: bench(fn() => $obj->methodToTest(), 'Some label if you want');
*
* @param \Closure $fn
* @param string $name
* @return mixed
*/
function bench(\Closure $fn, $label = 'anonymous') {
$starttime = array_sum(explode(" ", microtime()));
$result = $fn();
$endtime = round((array_sum(explode(" ", microtime())) - $starttime)*1000, 1);
echo "<hr/> Benchmark ($label) : ".$endtime." ms<br/>";
return $result;
}