cast-class
Code (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
* Cast class
*
* @author iltar van der berg
* @version 1.1
* @name Cast
*/
/**
* Class to Cast var types to another
*/
class Cast
{
/**
* cast to string
*
* @param mixed $input
* @return string
*/
static public function string(&$input)
{
return $input = (string) sprintf('%s', $input);
}
/**
* cast to integer
*
* @param mixed $input
* @return int
*/
static public function int(&$input)
{
return $input = (int) sprintf('%d', $input);
}
/**
* cast to float
*
* @param mixed $input
* @return float
*/
static public function float(&$input)
{
return $input = (float) sprintf('%.F', $input);
}
/**
* cast to scientific
*
* @param mixed $input
* @return double
*/
static public function scientific(&$input)
{
return $input = (double) sprintf('%.e', $input);
}
/**
* cast to binary
*
* @param mixed $input
* @return int
*/
static public function binary(&$input)
{
return $input = (version_compare(PHP_VERSION, '6.0.0dev', '>='))
? (binary) sprintf('%b', $input)
: (int) sprintf('%b', $input);
}
/**
* cast to hexadecimal
*
* @param mixed $input
* @return int
*/
static public function hexadecimal(&$input)
{
return $input = sprintf('%X', $input);
}
/**
* Cast to boolean
*
* @param mixed $input
* @return boolean
*/
static public function bool(&$input)
{
return $input = (bool) $input;
}
/**
* Cast to array
*
* @param mixed $input
* @return array
*/
static public function _array(&$input)
{
return $input = (array) $input;
}
}
?>
/**
* Cast class
*
* @author iltar van der berg
* @version 1.1
* @name Cast
*/
/**
* Class to Cast var types to another
*/
class Cast
{
/**
* cast to string
*
* @param mixed $input
* @return string
*/
static public function string(&$input)
{
return $input = (string) sprintf('%s', $input);
}
/**
* cast to integer
*
* @param mixed $input
* @return int
*/
static public function int(&$input)
{
return $input = (int) sprintf('%d', $input);
}
/**
* cast to float
*
* @param mixed $input
* @return float
*/
static public function float(&$input)
{
return $input = (float) sprintf('%.F', $input);
}
/**
* cast to scientific
*
* @param mixed $input
* @return double
*/
static public function scientific(&$input)
{
return $input = (double) sprintf('%.e', $input);
}
/**
* cast to binary
*
* @param mixed $input
* @return int
*/
static public function binary(&$input)
{
return $input = (version_compare(PHP_VERSION, '6.0.0dev', '>='))
? (binary) sprintf('%b', $input)
: (int) sprintf('%b', $input);
}
/**
* cast to hexadecimal
*
* @param mixed $input
* @return int
*/
static public function hexadecimal(&$input)
{
return $input = sprintf('%X', $input);
}
/**
* Cast to boolean
*
* @param mixed $input
* @return boolean
*/
static public function bool(&$input)
{
return $input = (bool) $input;
}
/**
* Cast to array
*
* @param mixed $input
* @return array
*/
static public function _array(&$input)
{
return $input = (array) $input;
}
}
?>