[php-src] Issue #18760: Type inconsistency between the filter_var function and it's callback on the $value parameter.

From: Date: Wed, 04 Jun 2025 17:19:06 +0000
Subject: [php-src] Issue #18760: Type inconsistency between the filter_var function and it's callback on the $value parameter.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250205@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/18760 Author: tonurics ### 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._ ```php <?php unset($json); $json=filter_var( value:$_POST['array'], filter:FILTER_CALLBACK, options:[ 'options'=>function( mixed $value, ):string{ 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 ```plain 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

« previous php.bugs (#250205) next »