Type inconsistency between the filter_var function and it's callback on the $value parameter.
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Description
The filter_var function has the following description:
filter_var(mixed $value, int $filter = FILTER_DEFAULT, array|int $options = 0): mixed
The "callback signature" [description] of the User Defined Filter of the FILTER_CALLBACK filter is:
callback(string $value): mixed
Problem:
This inconsistency prevents FILTER_CALLBACK from being used to sanitize arrays, such as those set in the predefined variables after an HTTP POST request.
e.g.: The following code generates a type error. [EDIT 2025-06-09:] The code sample in this post does not demonstrate the reported problem, see updated sample here: https://github.com/php/doc-en/issues/4726
<?php
unset($json);
$json=filter_var(
value:$_POST['array'],
filter:FILTER_CALLBACK,
options:[
'options'=>function(
mixed $value,
):mixed{
return json_encode($value);
},
],
);
Solution:
The type of the $value parameter in the "callback signature" [description] should be changed to match its filter_var calling function. i.e.:
callback(mixed $value): mixed
PHP Version
PHP 8.4.7 (cli) (built: May 9 2025 07:02:39) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies
with Zend OPcache v8.4.7, Copyright (c), by Zend Technologies
Operating System
Debian 6.1.140-1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the FILTER_CALLBACK User Defined Filter callback signature in the PHP documentation and compare it with the filter_var description. Update the documented value parameter type to match the supported filter_var input, then verify the rendered documentation and the reported array-sanitization example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100