Skip to content

Instantly share code, notes, and snippets.

@homleen
Last active December 18, 2015 06:58
Show Gist options
  • Save homleen/5742724 to your computer and use it in GitHub Desktop.
Save homleen/5742724 to your computer and use it in GitHub Desktop.
小心php中的弱比较
<?php
loose_comparison('github'); // github.com
strong_comparison('github'); // github.com
loose_comparison(0); // github.com
strong_comparison(0); // Oops! NSA...
function loose_comparison($str) {
switch ($str) {
case "github":
echo "github.com\n";
break;
case "google":
echo "google.com\n";
default:
echo "Oops! NSA...\n";
}
}
function strong_comparison($str) {
switch (strval($str)) {
case "github":
echo "github.com\n";
break;
case "google":
echo "google.com\n";
default:
echo "Oops! NSA...\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment