Blog

PHP – Problem with issetor()

In case you haven’t seen it before, issetor() is a quick and dirty way of getting a value from a variable that may or may not be defined: function issetor(&$var, $default=NULL) { return isset($var) ? $var : $default; } One unfortunate side-effect that most people are unaware of is that Read more…

By Chris West, ago
Blog

PHP Snippet – array_filter_keys()

While working on YourJS.com I was trying to figure out a quick way to use extract() to only convert some of the $_REQUEST values to variables in the symbol table. Then I realized I could use this: function array_filter_keys($array, $keys_to_include) { return array_intersect_key($array, array_flip($keys_to_include)); } Using this will give you Read more…

By Chris West, ago
Blog

JavaScript Snippet – getClass()

If you have been using JavaScript for a little bit you probably already know how to determine a variable’s class constructor, but just in case you are overthinking it here is a hint: variable.constructor. šŸ™‚ Of course, many times I like to make functions that will spit my results for Read more…

By Chris West, ago
Blog

JavaScript Quirks – Array Slicing Node Lists

For a while many developers, including myself, suggested that Array.prototype.slice() be used to turn any array-like object into an array. Recently, I was alerted to a scenario in which this does not work as expected. Let’s take the following code for example: var elems = document.body.getElementsByTagName('*'); var arrElems = Array.prototype.slice.call(elems, Read more…

By Chris West, ago