Skip to content

Commit

Permalink
add function is_countable() as a polyfill for environments with PHP <…
Browse files Browse the repository at this point in the history
… 7.3.0 (#357)

After this issue came up in this thread:
https://forum.wbce.org/viewtopic.php?pid=20226#p20226
I decided to implement this function into functions.php so it's ready to go, as checking with is_array() won't always do.

This function will be implemented in PHP since version 7.3.0.
This polyfill function will allow the use of this function also on environments with a PHP lower than 7.3.0
see also: http://php.net/manual/en/function.is-countable.php
  • Loading branch information
WebDesignWorx authored and Christoph Bleiweis committed Oct 30, 2018
1 parent ca56f3f commit a01a528
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion wbce/framework/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1267,4 +1267,22 @@ function url_encode($string)
$replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
return str_replace($entities, $replacements, rawurlencode($string));
}
}
}


/**
* is_countable()
* ==============
* This function will be implemented in PHP since version 7.3.0
* This polyfill function will allow the use of this function
* also on environments with a PHP lower than 7.3.0
* see also: http://php.net/manual/en/function.is-countable.php
*
* @param unspecified $uVar The variable you want to check
* @return bool true or false
*/
if (!function_exists('is_countable')) {
function is_countable($uVar) {
return (is_array($uVar) || $uVar instanceof Countable);
}
}

0 comments on commit a01a528

Please sign in to comment.