Created
April 22, 2020 12:05
-
-
Save kobus1998/e9828268e9f1d651c488a94c6d918ebb to your computer and use it in GitHub Desktop.
type casting class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class T | |
{ | |
public static function __callStatic($name, $arguments) | |
{ | |
if (isset($arguments[0])) { | |
if ($name == 'int') { | |
return (int) $arguments[0]; | |
} elseif ($name == 'string') { | |
return (string) $arguments[0]; | |
} elseif ($name == 'array') { | |
return (array) $arguments[0]; | |
} elseif ($name == 'object') { | |
return (object) $arguments[0]; | |
} elseif ($name == 'float') { | |
return (float) $arguments[0]; | |
} elseif ($name == 'bool') { | |
return (bool) $arguments[0]; | |
} | |
} | |
} | |
} | |
$o = new stdClass; | |
$o->a = 2; | |
print_r( T::array($o)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment