Created
July 14, 2016 12:50
-
-
Save ThijsFeryn/a59875c33129f1f8112fc98431d95216 to your computer and use it in GitHub Desktop.
Catch type errors in PHP 7
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 | |
declare(strict_types=1); | |
function double(int $argument):int { | |
return $argument*2; | |
} | |
try { | |
var_dump(double("3")); | |
} catch (TypeError $e) { | |
echo "A type error occured: ".$e->getMessage(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment