99
1010namespace Toolkit \Stdlib ;
1111
12+ use function gettype ;
13+
1214/**
1315 * Class Type - php data type
1416 *
1517 * @package Toolkit\PhpKit
18+ * @see \gettype()
1619 */
1720final class Type
1821{
19- // basic types
22+ // ------ basic types ------
23+
24+ // TIPS: not in gettype returns.
2025 public const INT = 'int ' ;
2126
2227 public const INTEGER = 'integer ' ;
@@ -25,21 +30,51 @@ final class Type
2530
2631 public const DOUBLE = 'double ' ;
2732
33+ // TIPS: not in gettype returns.
2834 public const BOOL = 'bool ' ;
2935
3036 public const BOOLEAN = 'boolean ' ;
3137
3238 public const STRING = 'string ' ;
3339
34- // complex types
40+ // ------ complex types ------
3541 public const ARRAY = 'array ' ;
3642
3743 public const OBJECT = 'object ' ;
3844
3945 public const RESOURCE = 'resource ' ;
4046
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+
4175 /**
4276 * @return array
77+ * @see \gettype()
4378 */
4479 public static function all (): array
4580 {
0 commit comments