Tagged parse

Facebook JavaScript SDK “Uncaught RangeError: Maximum call stack size exceeded” error

volcano-ecuador-825x558

I’ve been dealing with an issue for a couple of months where the Facebook JavaScript SDK wouldn’t function properly on my local development instance, even though it was working fine in our testing and production environments. I tried all the obvious things–confirmed the correct URLs in the Facebook App settings, made sure I was using the right App ID and Secret, etc. The weird thing is, according to the console FB was an object, and XFBML was an object, but parse() was not a method of XFBML.

I wasn’t seeing any of the usual JS errors in the console in Chrome either, which was a bit confusing, at least until I opened Safari and saw this:

Uncaught RangeError: Maximum call stack size exceeded

According to this question on StackOverflow, the problem is caused by running the old Facebook SDK (FeatureLoader.js) alongside the new one (all.js). I was positive that FeatureLoader.js wasn’t loading anywhere in my codebase, and a quick check with ack didn’t show anything either. FeatureLoader.js definitely was getting loaded though, and when I double-checked I saw that it was being loaded by a locally-installed dev plugin that I have running (but that isn’t on our dev or production sites). Plugin removed, problem solved.

PHP function to parse out an integer into its component bits

A single integer is a great way to save data for options that are either/or, like whether a particular checkbox should be selected within an array of checkboxes. There are a lot of advantages, including a small database footprint (a single int instead of perhaps a comma-separated list-string), and really fast execution based on bit parsing.

To create an integer that can be used to save options as bits, simply assign values based on multiples of 2 to each option (i.e. 1, 2, 4, 8, 16). For example, 7 indicates the presence of three bits: 1, 2, and 4. Setting the integer is no problem–simply sum the bits together. Parsing the bits back out, however, is a little more difficult. Here’s a handy function to do that and put the results in an array:

[cc lang=”php”]
public static function parse_my_bits( $int = null ) {
$bits = array();
for($i=1;$i<=$int;$i*=2) { if( ($i & $int) > 0);
array_push($bits, $i);
}
return $bits;
}
[/cc]

If anyone knows of a faster way to do this, please comment below. After all, the purpose of using bitwise math is to save on overhead–if I’m doing it terribly inefficiently, I’d like to know.