9
9
10
10
namespace Toolkit \Stdlib ;
11
11
12
+ use function gettype ;
13
+
12
14
/**
13
15
* Class Type - php data type
14
16
*
15
17
* @package Toolkit\PhpKit
18
+ * @see \gettype()
16
19
*/
17
20
final class Type
18
21
{
19
- // basic types
22
+ // ------ basic types ------
23
+
24
+ // TIPS: not in gettype returns.
20
25
public const INT = 'int ' ;
21
26
22
27
public const INTEGER = 'integer ' ;
@@ -25,21 +30,51 @@ final class Type
25
30
26
31
public const DOUBLE = 'double ' ;
27
32
33
+ // TIPS: not in gettype returns.
28
34
public const BOOL = 'bool ' ;
29
35
30
36
public const BOOLEAN = 'boolean ' ;
31
37
32
38
public const STRING = 'string ' ;
33
39
34
- // complex types
40
+ // ------ complex types ------
35
41
public const ARRAY = 'array ' ;
36
42
37
43
public const OBJECT = 'object ' ;
38
44
39
45
public const RESOURCE = 'resource ' ;
40
46
47
+ // TIPS: since 7.2.0
48
+ public const RESOURCE_CLOSED = 'resource (closed) ' ;
49
+
50
+ // ------ other type names ------
51
+
52
+ public const CALLABLE = 'callable ' ;
53
+
54
+ public const MiXED = 'mixed ' ;
55
+
56
+ public const UNKNOWN = 'unknown type ' ;
57
+
58
+ /**
59
+ * @param mixed $val
60
+ *
61
+ * @return string
62
+ */
63
+ public static function get ($ val ): string
64
+ {
65
+ $ typName = gettype ($ val );
66
+ if ($ typName === self ::UNKNOWN ) {
67
+ $ typName = self ::MiXED;
68
+ } elseif ($ typName === self ::RESOURCE_CLOSED ) {
69
+ $ typName = self ::RESOURCE ;
70
+ }
71
+
72
+ return $ typName ;
73
+ }
74
+
41
75
/**
42
76
* @return array
77
+ * @see \gettype()
43
78
*/
44
79
public static function all (): array
45
80
{
0 commit comments