Home » PHP » PHP Filters Advanced » Question
  1. What will be the output of the following PHP code?
    <?php
    $var = 'vehicle';
    $Res = filter_var($var, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
    echo $Res;
    ?>
    1. Error
    2. Null
    3. True
    4. False
    5. None of these
Correct Option: B

There is an undocumented filter flag for FILTER_VALIDATE_BOOLEAN. The documentation implies that it will return NULL if the value doesn’t match the allowed true/false values. However this doesn’t happen unless you give it the FILTER_NULL_ON_FAILURE flag.



Your comments will be displayed only after manual approval.