Skip to content

Instantly share code, notes, and snippets.

@rogierslag
Created May 1, 2014 09:57
Show Gist options
  • Save rogierslag/37db78843ceccb523d9a to your computer and use it in GitHub Desktop.
Save rogierslag/37db78843ceccb523d9a to your computer and use it in GitHub Desktop.
Hack type safety
<?hh //strict
function newline() : void {
echo "\n";
}
function number() : int {
return 123;
}
function string() : string {
return "123test";
}
function main() : void {
var_dump(number() == string()); //true
var_dump(number() === string()); //false
newline();
var_dump(string() == number()); //true
var_dump(string() === number()); //false
newline();
var_dump(string() == A::JUST_A_NICE_CONSTANT); //true
var_dump(string() === A::JUST_A_NICE_CONSTANT); //false
}
class A { const int JUST_A_NICE_CONSTANT = 123; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment