Skip to content

Instantly share code, notes, and snippets.

@rhagni
Created July 11, 2016 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhagni/45252e9ede8417de5b6d16a4699a979f to your computer and use it in GitHub Desktop.
Save rhagni/45252e9ede8417de5b6d16a4699a979f to your computer and use it in GitHub Desktop.
Difference between floor and bitwise OR, normally used to check status code of a request, being of category 2xx
<?php
// https://3v4l.org/XCGmc
$code = 204;
$equals_to = 2;
// define("DEBUG", 1);
function debug()
{
if (!defined("DEBUG") || !func_num_args()) {
return;
}
call_user_func_array("var_dump", func_get_args());
}
$equals = function ($v) {
debug($v);
return $v == $GLOBALS["equals_to"];
};
$strict = function ($v) {
debug($v);
return $v === $GLOBALS["equals_to"];
};
function floor_n($v) {
debug($v);
return floor($v);
}
function floor_bw($v) {
debug($v);
return 0 | $v;
}
$functions = ["floor_n", "floor_bw"];
$operators = [$equals, $strict];
foreach ($functions as $function) {
foreach ($operators as $operator) {
var_dump($operator($function($code / 100)));
echo "\r\n";
}
echo "\r\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment