cannot use both FILTER_NULL_ON_FAILURE and FILTER_THROW_ON_FAILURE¶
Description¶
There are two options for the filter extension to handle errors: either return null, or throw an exception. They are mutually exclusive, and can’t be used at the same time.
Example¶
<?php
// combining constants with |
filter_var( value: 'bob@example.com',
filter: FILTER_VALIDATE_EMAIL,
options: FILTER_NULL_ON_FAILURE | FILTER_THROW_ON_FAILURE,
);
// combining constants with +
filter_var( value: 'bob@example.com',
filter: FILTER_VALIDATE_EMAIL,
options: FILTER_NULL_ON_FAILURE + FILTER_THROW_ON_FAILURE,
);
// FILTER_NULL_ON_FAILURE + FILTER_THROW_ON_FAILURE = 402653184
filter_var( value: 'bob@example.com',
filter: FILTER_VALIDATE_EMAIL,
options: 402653184,
);
?>
Solutions¶
Use only one of the two constants.
When providing the options as an integer, make sure the bytes 27 and 28 are not set at the same time.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.