Using filter_var for boolean environment variables

Submitted by charles on

Someone on my team added the following setting to check whether an environment variable was true or false:

$settings['x_menu_admin_enable'] = strtolower(getenv('X_MENU_ADMIN_ENABLE')) === 'true' ? getenv('X_MENU_ADMIN_ENABLE') : FALSE;

I find that using PHPs filter_var makes this code a bit easier to parse and only calls getenv once:

$settings['x_menu_admin_enable'] = filter_var(getenv('X_MENU_ADMIN_ENABLE'), FILTER_VALIDATE_BOOLEAN);

Read more about the function and the types of filters