Created
April 13, 2012 19:46
-
-
Save miholeus/2379592 to your computer and use it in GitHub Desktop.
PHP type hinting
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
set_error_handler('handle'); | |
function foo(integer $p1, bool $p2) { | |
echo "ok" . PHP_EOL; | |
} | |
$param1 = 123; | |
$param2 = 'string val!'; | |
foo($param1, $param2); | |
function handle($lvl, $msg) | |
{ | |
static $_types = array( | |
'boolean,' => 'boolean', | |
'bool,' => 'boolean', | |
'integer,' => 'integer', | |
'int,' => 'integer', | |
'float,' => 'float', | |
'double,' => 'float', | |
'real,' => 'float', | |
'string,' => 'string', | |
'resource,' => 'resource' | |
); | |
if ($lvl == E_RECOVERABLE_ERROR) { | |
$errmsg = explode(' ', $msg, 13); | |
if (isset($_types[$errmsg[10]]) && $_types[$errmsg[10]] == $errmsg[11]) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment