| 1 |
<?php |
| 2 |
|
| 3 |
namespace Safe; |
| 4 |
|
| 5 |
use Safe\Exceptions\VarException; |
| 6 |
|
| 7 |
/** |
| 8 |
* Set the type of variable var to |
| 9 |
* type. |
| 10 |
* |
| 11 |
* @param mixed $var The variable being converted. |
| 12 |
* @param string $type Possibles values of type are: |
| 13 |
* |
| 14 |
* |
| 15 |
* |
| 16 |
* "boolean" or "bool" |
| 17 |
* |
| 18 |
* |
| 19 |
* |
| 20 |
* |
| 21 |
* "integer" or "int" |
| 22 |
* |
| 23 |
* |
| 24 |
* |
| 25 |
* |
| 26 |
* "float" or "double" |
| 27 |
* |
| 28 |
* |
| 29 |
* |
| 30 |
* |
| 31 |
* "string" |
| 32 |
* |
| 33 |
* |
| 34 |
* |
| 35 |
* |
| 36 |
* "array" |
| 37 |
* |
| 38 |
* |
| 39 |
* |
| 40 |
* |
| 41 |
* "object" |
| 42 |
* |
| 43 |
* |
| 44 |
* |
| 45 |
* |
| 46 |
* "null" |
| 47 |
* |
| 48 |
* |
| 49 |
* |
| 50 |
* @throws VarException |
| 51 |
* |
| 52 |
*/ |
| 53 |
function settype(&$var, string $type): void |
| 54 |
{ |
| 55 |
error_clear_last(); |
| 56 |
$result = \settype($var, $type); |
| 57 |
if ($result === false) { |
| 58 |
throw VarException::createFromPhpError(); |
| 59 |
} |
| 60 |
} |
| 61 |
|