Skip to content

Instantly share code, notes, and snippets.

@ThijsFeryn
Created July 14, 2016 12:50
Show Gist options
  • Save ThijsFeryn/a59875c33129f1f8112fc98431d95216 to your computer and use it in GitHub Desktop.
Save ThijsFeryn/a59875c33129f1f8112fc98431d95216 to your computer and use it in GitHub Desktop.
Catch type errors in PHP 7
<?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