Wordpress Snippets

Call to undefined function boolval()

boolval() is a PHP function that was introduced in PHP 5.5. If you try to use it on a server that runs PHP 5.4 and lower, you will get an error like this:

Fatal error: Call to undefined function boolval() in /path/to/file/file.php on line 12

To fix this error, add the following to your WordPress theme’s functions.php

/**
 * Get the boolean value of a variable
 *
 * @param 	mixed 	The scalar value being converted to a boolean.
 * @return 	boolean The boolean value of var.
 * @refer	http://php.net/manual/en/function.boolval.php#114013
 */
if( !function_exists('boolval')) {
  
  function boolval($var){
    return !! $var;
  }
}

Let me know if that helps.

Hire Us. Or just say Hi!
Need a job? Apply to get one.